Santhosh
Santhosh

Reputation: 11778

postgresql: cannot run inside a transaction block

I am trying to run these commands together in SQLbox of phppgadmin

CREATE DATABASE "ir-staging";
CREATE USER django WITH ENCRYPTED PASSWORD 'django';
GRANT ALL PRIVILEGES ON DATABASE "ir-staging" TO django;

I get

SQL error:

ERROR:  CREATE DATABASE cannot run inside a transaction block
In statement:
CREATE DATABASE "ir-staging";
CREATE USER django WITH ENCRYPTED PASSWORD 'django';
GRANT ALL PRIVILEGES ON DATABASE "ir-staging" TO django

Whereas if I run the

CREATE DATABASE "ir-staging";

alone it works

Upvotes: 0

Views: 8193

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19655

Pretty straight forward:

https://www.postgresql.org/docs/current/sql-createdatabase.html

CREATE DATABASE cannot be executed inside a transaction block.

From the looks of it Sqlbox is starting a transaction with BEGIN; when running multiple statements and tripping the error. Whereas for single transaction it is running in autocommit mode. Look in the docs to see if you can specify autocommit as default action. Or better yet use psql instead.

Upvotes: 1

Related Questions