Whereas How to drop a table based on IF condition in postgres? solves the problem of conditionally dropping a table, it doesn't work for dropping a database because:
ERROR: DROP DATABASE cannot be executed from a function
I want to drop a database but only if it is has no user tables.
How can I execute any kind of IF if I can't do it from function?
DROP DATABASEnot being allowed in a transaction. Functions run in a transaction, hence the error. This is going to be something you need to do from outside Postgres using a script.IFcontrol out of the postgres script into the hosting shell script; and then I can ask psql to drop database unconditionally