如何处理类似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
之前已创建。
e.pgerror
为None。
if print(e) == "no result to fetch"
无效
我将运行带有返回值的不同脚本,而没有返回值。脚本什么也不返回时如何处理?
UPDATE:cursor.description
工作方式
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)
cursor.description
正在工作