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

asked Jul 4, 2022 at 7:29
1
  • in psql you can use \l Commented 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');
answered Jul 4, 2022 at 7:47
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.