DBeaver / PostgreSQL: "Error: database already exists", but I can't find it
May 23
I want to create database called "President" by rightclicking on PostgreSQL and selecting Create Database.
However, I get the error in the screenprint below.
I can create databases with other names like SomeOtherDatabase and SomeOtherDatabase2 (see screenprints).
Any ideas how I can find and delete the database "President" that seems to exist already?
UPDATE!!
If I execute
select * from pg_database
I get the following result:
So database "President" does seem to exist. (Meanwhile I deleted someOtherDatabase and someOtherDatabase2.)
However, if I execute
drop database President
I get:
1 answer
Accepted answer · original discussion
May 23
You can query catalog view pg_database to check if the database already exists:
select datname from pg_database WHERE datname = 'president'
And drop it with drop database:
drop database president;
Note that Postgres' drop database syntax supports the if exists clause, which may come handy in your use case:
drop database if exists president;
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.