PostgreSQL – Better Way to List All Databases Except ‘postgres’

postgresqlselectwhere

SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn = true And datname NOT IN ('postgres')

Using the code above, I get all the databases except postgres as shown in the image below:
All databases in Postgres

Is there any better/cleaner/nicer way than my code above to get the same result?

Best Answer

There is no real improvement possible, but I think the following is more readable:

SELECT datname
FROM pg_database
WHERE NOT datistemplate
  AND datallowconn
  AND datname <> 'postgres';