I am trying to execute this query with psycopg2 in Python3:
query_clone_db_data = (
'CREATE DATABASE (%s) WITH TEMPLATE (%s) OWNER (%s);'
)
conn.cursor.execute(query_clone_db_data, (new_dbname, original_dbname, owner, ))
And I am getting this error message:
syntax error at or near "'my_new_database'" LINE 1: CREATE DATABASE ('my_new_database') WITH TEMPLATE 'original...
On the other hand, this query works without any problem:
query_get_owner_dbs = (
'SELECT d.datname, d.datallowconn, '
'pg_catalog.pg_get_userbyid(d.datdba) as owner '
'FROM pg_catalog.pg_database d '
'WHERE pg_catalog.pg_get_userbyid(d.datdba) = (%s);'
)
conn.cursor.execute(query_get_owner_dbs, (owner, ))
Why the second one has not syntax errors and the first one yes? I tried to remove parenthesis in the first one and then the problem is the quotes... Anyone knows what is happening?