5

When i run this SQL query via psql client it runs for several seconds (~90 seconds, that's normal since its a huge table) and it return, then i can check that my line is successfully inserted.

SELECT merge_data('898989', '111111111', '10000')

It is a stored procedure that runs an UPDATE or INSERT, the procedure is ran without errors and i get my entry in the table.

When trying to do the same from a python program, the query take 2 seconds and returns no errors, i get nothing in my table; for information, the statement is successfully executed on postgresqk backed (i can see it in pgsql logs), here's my code snippet:

conn = psycopg2.connect("...")
cursor = conn.cursor()

try:
    cursor.callproc("merge_data", ['898989', '111111111', '10000'])
except:
    print "ERROR !"

cursor.close()

2 Answers 2

6

Resolved !

By default, psycopg2 doesnt autocommit on each executed statement, so once i close the connection (at the end) all pending transactions are discarded as if a ROLLBACK was performed.

One may call conn.commit() after each cursor.execute() or .callproc, or just set it at a global scope using

conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
0

conn.commit() should be used instead changing the isolation level, unless you realy need the autocommit feature.

Python DB2 API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.