[ACCEPTED]-Using Postgres in a web app: "transaction aborted" errors-concurrency

Accepted answer
Score: 14

that error is caused because of a precedent 5 error. look at this piece of code:

>>> import psycopg2
>>> conn = psycopg2.connect('')
>>> cur = conn.cursor()
>>> cur.execute('select current _date')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.ProgrammingError: syntax error at or near "_date"
LINE 1: select current _date
                       ^

>>> cur.execute('select current_date')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block

>>> conn.rollback()
>>> cur.execute('select current_date')
>>> cur.fetchall()
[(datetime.date(2010, 2, 5),)]
>>> 

if you 4 are familiar with twisted, look at twisted.enterprise.adbapi for 3 an example how to handle cursors. basically 2 you should always commit or rollback your 1 cursors:

try:
    cur.execute("...")
    cur.fetchall()
    cur.close()
    connection.commit()
except:
    connection.rollback()

More Related questions