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
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);