ads' corner

role ... cannot be dropped because some objects depend on it

I want to drop a ROLE (previously USER/GROUPs) which is still referenced by object(s) in my database. But PostgreSQL has objections:


create language if not exist

In a customer project I have to setup a database from a Makefile. Part of my problem: on Windows the installer may or may not install plpgsql into template1, therefore in consequence this language may or may not be activated in every new database. But that’s not predictable. This problem can appear on different Linux/Unix distributions too.


Understanding SQL

Have to port a phpkit database to something else. It seems, the phpkit ppl did not really understand what SQL is for.


table size, database size

I have seen this question more than once in the past: “How much storage space do I need for my table?”

PostgreSQL can give you this information.


Avoid autovacuum for entire databases

We have a database with production data for a platform and another database with a production database dump for testing queries. We also have a test database but this one has slightly different DDL, because it’s for developing new features. Now Autovacuum is running on this server and keeps vacuuming this test database.


Avoid Unique Key violation

If you have a table with an unique key field, want to insert new values but you don’t know if the value may already be in the table, you can use the following query:


Reverse a text in PostgreSQL

I’m always searching for a reverse function in PostgreSQL, so here is the link:


find the sequence name

Because I always forget this function name: