Re: [HACKERS] jsonb_set array append hack?

2015-10-03 Thread Andrew Dunstan
On 10/03/2015 04:49 PM, Peter Geoghegan wrote: On Mon, Sep 21, 2015 at 2:21 PM, Andrew Dunstan wrote: Thanks for the explanation. So, basically, it should be like this, am I right? postgres=# SELECT jsonb_set( '{"name": "Joe", "vehicle_types": ["car", "van"]}'::jsonb, '{vehicle_typ

Re: [HACKERS] jsonb_set array append hack?

2015-10-03 Thread Peter Geoghegan
On Mon, Sep 21, 2015 at 2:21 PM, Andrew Dunstan wrote: >> Thanks for the explanation. So, basically, it should be like this, am I >> right? >> >> postgres=# SELECT jsonb_set( >> '{"name": "Joe", "vehicle_types": ["car", "van"]}'::jsonb, >> '{vehicle_types, nonsense}', >> '"motorcycle"'

Re: [HACKERS] jsonb_set array append hack?

2015-09-24 Thread Dmitry Dolgov
>> For that matter, we should probably disallow NULL path elements also, shouldn't we? > I'd say yes. Well, here is the new `setPath` function with this modification. Is it what did you mean? non_integer_in_path2.patch Description: Binary data -- Sent via pgsql-hackers mailing list (pgsql-hack

Re: [HACKERS] jsonb_set array append hack?

2015-09-21 Thread Thom Brown
On 21 September 2015 at 22:21, Andrew Dunstan wrote: > > > On 09/21/2015 12:13 PM, Dmitry Dolgov wrote: > >> > I would expect some kind of error. We're trying to address a position >> in an array, and we're instead passing a key. If it completes >> successfully, the chances are it isn't what th

Re: [HACKERS] jsonb_set array append hack?

2015-09-21 Thread Andrew Dunstan
On 09/21/2015 12:13 PM, Dmitry Dolgov wrote: > I would expect some kind of error. We're trying to address a position in an array, and we're instead passing a key. If it completes successfully, the chances are it isn't what the user intended. Thanks for the explanation. So, basically, it sh

Re: [HACKERS] jsonb_set array append hack?

2015-09-21 Thread Dmitry Dolgov
> I would expect some kind of error. We're trying to address a position in an array, and we're instead passing a key. If it completes successfully, the chances are it isn't what the user intended. Thanks for the explanation. So, basically, it should be like this, am I right? postgres=# SELECT j

Re: [HACKERS] jsonb_set array append hack?

2015-09-20 Thread Thom Brown
On 20 September 2015 at 16:17, Dmitry Dolgov <9erthali...@gmail.com> wrote: > I'm sorry, but I'm not sure, what behavior is expected in this case? > Right now the following logic was implemented: > "we trying to set an element inside an array, but we've got a > non-integer path item > ("no

Re: [HACKERS] jsonb_set array append hack?

2015-09-20 Thread Dmitry Dolgov
I'm sorry, but I'm not sure, what behavior is expected in this case? Right now the following logic was implemented: "we trying to set an element inside an array, but we've got a non-integer path item ("nonsense" in this particular case), so we're going to add a new element at the end of arr

Re: [HACKERS] jsonb_set array append hack?

2015-09-14 Thread Andrew Dunstan
On 09/14/2015 01:29 PM, Thom Brown wrote: Hi, I've noticed that if you use a string for an element key in jsonb_set with create_missing set to true, you can use it to append to an array: postgres=# SELECT jsonb_set( '{"name": "Joe", "vehicle_types": ["car","van"]}'::jsonb, '{vehi

[HACKERS] jsonb_set array append hack?

2015-09-14 Thread Thom Brown
Hi, I've noticed that if you use a string for an element key in jsonb_set with create_missing set to true, you can use it to append to an array: postgres=# SELECT jsonb_set( '{"name": "Joe", "vehicle_types": ["car","van"]}'::jsonb, '{vehicle_types,nonsense}', '"motorcycle"',

[HACKERS] jsonb_set

2015-05-26 Thread Andrew Dunstan
Here is the latest version of the refinement of jsonb_replace into jsonb_set. All known bugs have been fixed, and the only issue is the default value of the fourth parameter. Currently it's set to false, but I gather from the previous responses that the consensus is to make it true. cheers an

Re: [HACKERS] jsonb_set: update or upsert default?

2015-05-23 Thread Andrew Dunstan
On 05/23/2015 04:03 PM, Petr Jelinek wrote: On 23/05/15 17:59, David E. Wheeler wrote: On May 22, 2015, at 7:22 PM, Andrew Dunstan wrote: The proposed flag for jsonb_set (the renamed jsonb_replace) in the patch I recently published is set to false, meaning that the default behaviour is to r

Re: [HACKERS] jsonb_set: update or upsert default?

2015-05-23 Thread Petr Jelinek
On 23/05/15 17:59, David E. Wheeler wrote: On May 22, 2015, at 7:22 PM, Andrew Dunstan wrote: The proposed flag for jsonb_set (the renamed jsonb_replace) in the patch I recently published is set to false, meaning that the default behaviour is to require all elements of the path including the

Re: [HACKERS] jsonb_set: update or upsert default?

2015-05-23 Thread David E. Wheeler
On May 22, 2015, at 7:22 PM, Andrew Dunstan wrote: > The proposed flag for jsonb_set (the renamed jsonb_replace) in the patch I > recently published is set to false, meaning that the default behaviour is to > require all elements of the path including the last to be present. What that > does i

[HACKERS] jsonb_set: update or upsert default?

2015-05-22 Thread Andrew Dunstan
The proposed flag for jsonb_set (the renamed jsonb_replace) in the patch I recently published is set to false, meaning that the default behaviour is to require all elements of the path including the last to be present. What that does is effectively UPDATE for jsonb. If the flag is true, then