I want to create Postgres database using Python.
con = psql.connect(dbname='postgres',
user=self.user_name, host='',
password=self.password)
cur = con.cursor()
cur.execute("CREATE DATABASE %s ;" % self.db_name)
I am getting the following error:
InternalError: CREATE DATABASE cannot run inside a transaction block
I am using psycopg2 to connect. I don't understand what's the problem.
What am I trying to do is to connect to database (Postgres):
psql -postgres -U UserName
And then create another database:
create database test;
This is what I usually do and I want to automate this by creating Python script.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…