How can I handle error like psycopg2.ProgrammingError:
try
cursor.execute("CREATE TEMP TABLE temp_table1 AS SELECT 11 as a, 22 as b, 'Count' as unit; DROP TABLE temp_table1;")
data = cursor.fetchall()
except psycopg2.ProgrammingError as e:
if print(e) == "no result to fetch":
print("Skip Error - {}".format(e)
else:
raise(e)
cursor
has been created before.
e.pgerror
is None.
if print(e) == "no result to fetch"
doesn't work
I will be run different scripts with returned value and with doesn't. How can I handle the situation when the script returns nothing?
UPDATE:
cursor.description
is working way
try
cursor.execute("CREATE TEMP TABLE temp_table1 AS SELECT 11 as a, 22 as b, 'Count' as unit; DROP TABLE temp_table1;")
if cursor.description:
data = cursor.fetchall()
except psycopg2.ProgrammingError as e:
if print(e) == "no result to fetch":
print("Skip Error - {}".format(e)
else:
raise(e)