0

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..

1
  • in psql you can use \l
    – jian
    Jul 4, 2022 at 9:31

1 Answer 1

3

There 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');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.