[Solved]-Returning a value with psycopg2

25👍

Sure it will, it’ll know the ID as soon as the command finishes, that’s how RETURNING is implemented. You need to actually fetch it though, so something like:

cursor.execute("INSERT INTO .... RETURNING id")
id_of_new_row = cursor.fetchone()[0]

should work in your scenario.

3👍

RETURNING works on Postgresql >= 8.2

👤Ignus

Leave a comment