jsonb_set for nested new item?

From: Deven Phillips <deven(dot)phillips(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: jsonb_set for nested new item?
Date: 2016-09-23 14:14:57
Message-ID: CAJw+4NA7y-baCDJPkR-0MvxcrUW9qJbGb71MHzJYKs180mz+Sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there a way to set a nested element for which the parent paths do not
yet exist?

For example, if I have a JSONB value called 'data':

{
"foo": "bar"
}

and run

jsonb_set(data, {'boo', 'baz'}, 'newvalue')

I would expect the output to be:

{
"foo": "bar",
"boo": {
"baz": "newvalue"
}
}

But that does not appear to work..

Any suggestions would be appreciated.

Deven

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Deven Phillips 2016-09-23 14:19:12 Re: jsonb_set for nested new item?
Previous Message Dorian Hoxha 2016-09-23 13:36:39 Re: Multiple inserts