0

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.