Is there a PostgreSQL function which takes a string/text and returns true if the database exists, and false otherwise?
PostgresSQL v12+, based on default postgresql versions in Ubuntu 18.04, 20.04 & 22.04..
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityThere is no builtin method, but you can run a SELECT query to get that. You need to connect to some database, e.g. postgres
select exists (select * from pg_database where datname = 'the_name');