Last active
March 30, 2018 21:52
-
-
Save jvehent/662dd9fd9cc99a8ea01c783ec26ea2f8 to your computer and use it in GitHub Desktop.
Batch updates in PostgreSQL using UPDATE...FROM statements
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
observatory=> SELECT id, sha256_subject_spki FROM certificates WHERE id > 300 AND id < 305; | |
id | sha256_subject_spki | |
-----+------------------------------------------------------------------ | |
301 | 3EE6B341402851B27E64021A3023AAC7C1A0D2DEF27D5BCE5C2DBEB0B22DCC71 | |
302 | 47C7A149CA82FA7BA940A4D711D010625C6CB0B748B17016C46E25CE7ACD2B0C | |
303 | 8AB4E88556CBF864A5E9FD50171CD4ED8424E8F0801B99E236C810915950AE4B | |
304 | 5E6E52E50B5B9012817E63178BCB63BDE23CF1CC1F9458CED9B93A2BBA7DC4C6 | |
(4 rows) | |
observatory=> UPDATE certificates SET sha256_subject_spki = newvalues.spki | |
observatory=> FROM ( VALUES (301, 'foo'), (302, 'bar'), (303, 'baz') ) | |
observatory=> AS newvalues (id, spki) | |
observatory=> WHERE certificates.id = newvalues.id; | |
UPDATE 3 | |
observatory=> SELECT id, sha256_subject_spki FROM certificates WHERE id > 300 AND id < 305; | |
id | sha256_subject_spki | |
-----+------------------------------------------------------------------ | |
301 | foo | |
302 | bar | |
303 | baz | |
304 | 5E6E52E50B5B9012817E63178BCB63BDE23CF1CC1F9458CED9B93A2BBA7DC4C6 | |
(4 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment