Last active
January 9, 2025 12:23
-
-
Save ValchanOficial/4484d9aa7795d5044bcb5f997def6ae1 to your computer and use it in GitHub Desktop.
[Postgres][jsonb_set][jsonb_insert] nested field
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
INSERT - jsonb_insert | |
update my_table | |
set my_column = jsonb_insert(my_column, '{field1, field2, newkey}', '"hello insert"') | |
where id = 1; | |
// SELECT result: {"field1": {"field2": {"newvalue": "hello insert"}}} | |
SET - jsonb_set | |
update my_table | |
set my_column = jsonb_set(my_column, '{field1, field2}', '{"existingKey":"bye hello value"}') | |
where id = 1; | |
// SELECT result: {"field1": {"field2": {"existingKey": "bye hello value"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment