Psycopg2 : Create A Table In A Stored Procedure Postgres
Stored Procedure : CREATE OR REPLACE FUNCTION try_create() RETURNS INT AS $$ BEGIN CREATE TABLE hello(id SERIAL PRIMARY KEY, name TEXT); RETURN 1; END ; $$ LANGUA
Solution 1:
You should commit the transaction, add the commands:
...
conn.commit()
conn.close()
Alternatively, you can set the connection in autocommit mode:
conn = psycopg2.connect(user='a', password='a', dbname='a')
conn.autocommit = True
cur = conn.cursor()
cur.callproc('try_create', ())
conn.close()
Read more about transactions in psycopg2.
Post a Comment for "Psycopg2 : Create A Table In A Stored Procedure Postgres"