문제

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 *;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top