Good job! As you probably guessed,
RETURNING can also be used in
UPDATE queries. It's quite similar to how it's used in
The teacher entered the wrong subject for the student Alan Stanley,
id = 10. Let's take a look:
SET subject = 'Italian'
WHERE student_id = 10
RETURNING subject AS new_subject;
This statement changes the exam subject from Spanish to Italian. Notice that the
RETURNING clause is placed at the end of the query. Using
RETURNING allows us to see the updated record.
Note that we used an alias for the name of the returning column. In PostgreSQL,
RETURNING returns values after they are changed by the
UPDATE statement. You can't display the old values in
UPDATE in PostgreSQL.
Look at the result: