Skip to content

Instantly share code, notes, and snippets.

@digitaldreamer
Forked from prestonp/query.sql
Created July 30, 2020 15:16
Show Gist options
  • Save digitaldreamer/8344083640adb02bcd738a6129c16143 to your computer and use it in GitHub Desktop.
Save digitaldreamer/8344083640adb02bcd738a6129c16143 to your computer and use it in GitHub Desktop.
postgres update return new values and old values
-- returning updated values and old values by using a sub-expression
update orders
set type = 'delivery'
where id = 3767
returning id, type, (
select type from orders where id = 3767
) as old_type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment