Created
November 12, 2019 15:23
-
-
Save slavama/993e2ef9c1d7293e220e8c42d8b7d954 to your computer and use it in GitHub Desktop.
postgresql bulk update
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
CREATE TABLE billing.mytable(id integer, name text); | |
INSERT INTO billing.mytable VALUES(1, '1'); | |
INSERT INTO billing.mytable VALUES(2, '2'); | |
INSERT INTO billing.mytable VALUES(3, '3'); | |
UPDATE billing.mytable | |
SET name = Q.name | |
FROM ( | |
SELECT (value->>0)::integer AS id, (value->>1)::decimal AS name | |
FROM json_array_elements('[[1, "100"], [2, "200"]]') | |
) Q | |
WHERE mytable.id = Q.id; | |
SELECT * FROM billing.mytable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment