Databases · Junior · Question 61 of 75
What does INSERT ... RETURNING id do in PostgreSQL?
- 1Returns the last
idin the table without inserting - ✓Correct answer: Inserts the row and returns the generated
idin the same query - 3Inserts the row only if
idis returned by the client
Explanation
It saves a round trip and avoids race conditions of 'insert, then select the max id'. RETURNING also works with UPDATE and DELETE.