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
-
in psql you can use \ljian– jian2022年07月04日 09:31:01 +00:00Commented Jul 4, 2022 at 9:31
1 Answer 1
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
user1822user1822
lang-sql