I am using Dbeaver to run queries for my database (postgresql). I am running two queries:
CREATE DATABASE example_db;
and before this query, I am running drop if exists query:
DROP DATABASE IF EXISTS example_db;
But, I am getting this error:
SQL Error [55006]: ERROR: cannot drop the currently open database
I know that I should disconnect the current database and connect to another database to run the drop query but I could not find any way to switch databases in postgresql.
I used \connect db_name but it didn't work because \connect command in an SQL script being executed in a context that does not recognize \connect as a valid command.
I researched use database but found out that it works in mysql but not in postgresql. I tried using "IF not exists" and then run ‘create database’ command but it also did not work out because create database cannot be run within a transaction block in postgresql.
In short, I couldn't find any way to connect to another database inside the script
What is the solution here?
databaseis an alias forschemaper MySQL Schema. Therefore you are creating new schemas in MySQL from a single connection. You can do that in Postgres also.