statusmessage
fetchall()やfetchone()ではなくstatusmessageを使う。
select文だとfetchall()で結果を表示できるが、insert文だとエラーを吐く。
import psycopg2
def insert_values(name, age):
conn = psycopg2.connect(host=HOST,
user=USER,
password=PASSWORD,
dbname=DBNAME,
port=PORT)
cur = conn.cursor()
cur.execute('INSERT INTO sample_table VALUES(%s, %s)', (name, age))
cur.execute(sql)
conn.commit()
print(cur.statusmessage)
if __name__ == "__main__":
insert_values('Taro', 5)
参考記事
stackoverflow
https://stackoverflow.com/questions/55400707/python3-psycopg2-no-results-to-fetch-using-returning
github issues
https://github.com/psycopg/psycopg2/issues/346