I'm trying to create dataBase in Postgre SQL Python, i got an error: CREATE DATABASE cannot run inside a transaction block. I have read that u need autocommit, but i already have it. What's the problem
try:
with psycopg2.connect(
host=host,
user=rootUser,
password=rootPassword,
) as connection:
connection.autocommit = True
with connection.cursor() as cursor:
cursor.execute(
("CREATE DATABASE " + db_name + """ WITH
OWNER = """ + user + """ ENCODING = 'UTF8'
CONNECTION LIMIT = -1
IS_TEMPLATE = False;""")
)
with psycopg2.connect(...) as connection:construct seems to render the autocommit setting non-functional. Defining and populating the "connection" variable the usual way does work.