I am using psycopg2 2.6.1
. I have a bunch of queries that I need to execute in sequence.
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
Suppose q1
fails with SSL connection has been closed unexpectedly
. Then my rest of the queries also fail with cursor already closed
. How can I ensure that if one query fails then the following queries are executed successfully.