我正在尝试使用 pyspark 代码中的 psycopg2 从 postgresql 表中删除记录。但我收到错误。不知道哪里出了问题。提前致谢
def delete_records(table,city_list,key):
connection = None
try:
connection = psycopg2.connect(host=host,
database=db,
user=user,
password=password)
cursor = connection.cursor()
delete_query = "Delete from " +table+ " where "+key+" in "+ str(tuple(city_list))
cursor.execute(delete_query)
connection.commit()
logger.debug("Record deleted successfully")
except (Exception, psycopg2.DatabaseError) as error :
logger.error("%s transction error Reverting all other operations of a transction ", error)
connection.rollback()
finally:
if connection is not None:
cursor.close()
connection.close()
logger.debug("PostgreSQL connection is closed")
delete_records(table_name,city_list,"id")
错误
'NoneType' object has no attribute 'rollback
请帮忙。提前致谢
叮当猫咪
相关分类