Created
September 13, 2018 11:28
-
-
Save berkayakcay/c1ef0848ce66be314060fb465b2cc23f to your computer and use it in GitHub Desktop.
PostgreSQL UPDATE table and get ids from UPDATED rows then INSERT INTO another table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
PostgreSQL | |
If you want to insert any column retaled with update query you can use this. | |
It gets ids from updated tables and then inter them into another table. | |
*/ | |
with rows AS ( | |
UPDATE product SET price = price * 1.10 | |
RETURNING id | |
) | |
INSERT INTO updated_product | |
SELECT * FROM rows; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment