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.
Baca Juga
- I'm Trying To Install Psycopg2 Onto Mac Os 10.6.3; It Claims It Can't Find "stdarg.h" But I Can See It's There; What Should I Do?
- Filter With Array Column With Postgres And Sqlalchemy
- I'm Trying To Install Psycopg2 Onto Mac Os 10.6.3; It Claims It Can't Find "stdarg.h" But I Can See It's There; What Should I Do?
Post a Comment for "Psycopg2 : Create A Table In A Stored Procedure Postgres"