我正在使用psycopg2 2.6.1
。我有一堆需要按順序執行的查詢。psycopg2:光標已關閉
conn = psycopg2.connect(database=redshift_database,
user=redshift_user,
password=os.environ.get("PGPASSWORD"),
host=redshift_cluster,
port=redshift_port)
cursor = conn.cursor()
queries = [q1, q2, q3....] ## a list of queries
for query in queries:
try:
cursor.execute(query)
except:
print e.message
假設q1
不合格SSL connection has been closed unexpectedly
。然後我的其餘查詢也以cursor already closed
失敗。我如何確保如果一個查詢失敗,那麼以下查詢將成功執行。
檢查此鏈接可能對您有幫助http://stackoverflow.com/questions/1281875/making-sure-that-psycopg2-database-connection-alive –