Great! Let's wrap up the
INTO syntax with some additional info. This syntax allows us to get a result from
DELETE statements. Take a look:
UPDATE post INTO score
SET thumbs_down = thumbs_down + 1
WHERE id = post_id
There are two things happening here: a regular update (which adds a downvote to a given post), and an assignment.
UPDATE (like both
DELETE) in PostgreSQL has an optional
RETURNING clause that allows it to return a result from this statement. Here, we return the number of downvotes after the update. You can use the
INTO variable syntax to store this result in a variable.