4

Hi guys I'm stuck on a problem for my first database on Postgres and I cannot find a solution, I tried to see if it was a matter of setting autocommit on but apparently from postgres 9.x it's an inconclusive operation. The documentation suggests that it might be an error on permissions or a full disk. This is the code

CREATE DATABASE datacamp_courses 
WITH 
OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'English_United States.1252'
LC_CTYPE = 'English_United States.1252'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;


CREATE TABLE datacamp_courses (
    course_id SERIAL PRIMARY KEY,
    course_name VARCHAR (50) UNIQUE NOT NULL,
    course_instructor VARCHAR (100) NOT NULL,
    topic VARCHAR (2) NOT NULL
    );

This is the error :

ERROR:  CREATE DATABASE cannot run inside a transaction block
SQL state: 25001

Any help would be greatly appreciated

2
  • 1
    Are you running both those statements together (either both of them selected or neither selected)? If so then run them one at a time - select/highlight the first one, run it, then same for the second one. Commented Mar 4, 2020 at 14:58
  • Turn off auto commit before running that statement Commented Mar 4, 2020 at 15:00

2 Answers 2

1

Message is self explanatory: you cannot create a database in a transaction.

You can try to run your statements in psql (CLI) with runs in AUTOCOMMIT by default: it will work but note that the table will be created in current database (by default postgres) which is maybe not what you want. If you want to create a database and a table in this new database you can try:

  create database mydb;
  \connect mydb
  create table test(c int);
Sign up to request clarification or add additional context in comments.

Comments

1

If you use the db browser in Intellij idea, select the auto commit field from the database settings you are connecting to.

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.