Created
February 1, 2022 15:42
-
-
Save jaz303/5a8af4a9e07f0fe1782be12ac7b73d35 to your computer and use it in GitHub Desktop.
json mutate
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
DROP TABLE IF EXISTS student; | |
CREATE TABLE student ( | |
id SERIAL PRIMARY KEY, | |
name VARCHAR(255), | |
state JSONB | |
); | |
INSERT INTO student (name, state) VALUES ('Bob', '{"completed": []}'); | |
UPDATE student SET state = jsonb_set(state, '{completed}', state->'completed' || '[1,2,3]', TRUE) WHERE name = 'Bob'; | |
UPDATE student SET state = jsonb_set(state, '{completed}', state->'completed' || '[4,5]', TRUE) WHERE name = 'Bob'; | |
SELECT * FROM student; |
Author
jaz303
commented
Feb 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment