[ACCEPTED]-Returning a value with psycopg2-psycopg2

Accepted answer
Score: 23

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

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

should work 1 in your scenario.

Score: 3

RETURNING works on Postgresql >= 8.2

0

More Related questions