Since this is homework, I'll leave something for you.
Single SQL statement
Start reading about the RETURNING
clause of the UPDATE
command in the manual.
Another alternative (for more complex scenarios) would be a data-modifying CTE. You still need the RETURNING
clause for that.
Or you could create a function you can call in a single statement, but that would violate your requirement of only using simple DML commands.
Single transaction
If more than a single statement is allowed, another option would be a simple UPDATE
plus simple SELECT
wrapped into a transaction.