Skip to content

Instantly share code, notes, and snippets.

@ValchanOficial
Last active January 9, 2025 12:23
Show Gist options
  • Save ValchanOficial/4484d9aa7795d5044bcb5f997def6ae1 to your computer and use it in GitHub Desktop.
Save ValchanOficial/4484d9aa7795d5044bcb5f997def6ae1 to your computer and use it in GitHub Desktop.
[Postgres][jsonb_set][jsonb_insert] nested field
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