I am inserting an item the usual way using cursor's execute. However, doing a cursor.fetchone()
afterwards throws a ProgrammaticError
saying no results could be fetched. I can see the item inserted into the database.
What is the issue here? I am opening a connection with a with
statement, and I am not calling commit
as this is taken care of in the with
statement.
Is there a way to retrieve the result that was just inserted into psycopg2
easily?
Most likely you didn't add a RETURNING *;
to your INSERT
statement.
So... try something like this:
INSERT INTO table
...
RETURNING *;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.