Created
June 5, 2012 03:08
-
-
Save jkatz/2872338 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CREATE TABLE a (id serial, x int); | |
INSERT INTO a (x) VALUES (5); | |
INSERT INTO a (x) VALUES (7); | |
INSERT INTO a (x) VALUES (11); | |
INSERT INTO a (x) VALUES (13); | |
--- first data | |
SELECT * FROM a; | |
--- return the old data rows from the result | |
WITH old_data AS ( | |
SELECT id, x | |
FROM a | |
) | |
UPDATE a | |
SET x = 1 | |
FROM old_data | |
WHERE old_data.id = a.id | |
RETURNING old_data.x; | |
-- show that data has been updated | |
SELECT * FROM a; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment