0

**psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block ** error occured after excution

import pandas as pd
conn = ...
cur = conn.cursor()
fb_csv_file = "File_path"
table = pd.read_csv(fb_csv_file, encoding = 'latin1')
try:
    for index,row in table.iterrows():
        sql =  'DELETE FROM public."tbl_Name"  WHERE "col_1" =\'' +str(row['col_1']) + '\' \
                    AND "col_2"=\'' + str(row['col_2'])+'\';'     
        cur.execute(sql)
        conn.commit()
except Exception as e :             
    print("Error  : ",e)

1 Answers1

0

This may be useful.

This is what Postgres does when a query produces an error and you try to run another query without first rolling back the transaction. (You might think of it as a safety feature, to keep you from corrupting your data.)

Source: https://stackoverflow.com/a/2979389/8074624

Gaurav Shimpi
  • 21
  • 1
  • 7
  • Thanks Gaurav for reply. I also tried that solution and executed rollback query in except body. But its not What I need. I need to execute DELETE query. – Kiran Thakur Feb 14 '20 at 11:46
  • I don't think your SQL-query is a valid one. can you print your SQL once and give me the traceback of error if any? – Gaurav Shimpi Feb 18 '20 at 12:12