[HACKERS] Jsonb array-style subscripting, generic version

2016-05-17 Thread Dmitry Dolgov
Hi With regard to previous conversations: http://www.postgresql.org/message-id/flat/CA+q6zcV8qvGcDXurwwgUbwACV86Th7G80pnubg42e-p9gsSf=g...@mail.gmail.com#CA+q6zcV8qvGcDXurwwgUbwACV86Th7G80pnubg42e-p9gsSf=g...@mail.gmail.com http://www.postgresql.org/message-id/flat/ca+q6zcx3mdxgcgdthzuyswh-apyhh

Re: [HACKERS] jsonb array-style subscripting

2015-08-20 Thread Jim Nasby
On 8/20/15 3:44 PM, Josh Berkus wrote: What could be added as an extension? A method for preventing duplicate object keys. Since I'm in the minority here lets just drop it. :) -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Data in Trouble? Get it in Treble! http://BlueTreble.c

Re: [HACKERS] jsonb array-style subscripting

2015-08-20 Thread Josh Berkus
On 08/20/2015 12:24 PM, Jim Nasby wrote: > On 8/17/15 4:25 PM, Josh Berkus wrote: >> On 08/17/2015 02:18 PM, Jim Nasby wrote: >>> >On 8/17/15 3:33 PM, Josh Berkus wrote: >>Again, how do we handle missing keys? Just return NULL? or ERROR? I'd >>prefer the former, but there will be

Re: [HACKERS] jsonb array-style subscripting

2015-08-20 Thread Andrew Dunstan
On 08/20/2015 03:24 PM, Jim Nasby wrote: On 8/17/15 4:25 PM, Josh Berkus wrote: On 08/17/2015 02:18 PM, Jim Nasby wrote: >On 8/17/15 3:33 PM, Josh Berkus wrote: >>Again, how do we handle missing keys? Just return NULL? or ERROR? I'd >>prefer the former, but there will be arguments the ot

Re: [HACKERS] jsonb array-style subscripting

2015-08-20 Thread Jim Nasby
On 8/17/15 4:25 PM, Josh Berkus wrote: On 08/17/2015 02:18 PM, Jim Nasby wrote: >On 8/17/15 3:33 PM, Josh Berkus wrote: >>Again, how do we handle missing keys? Just return NULL? or ERROR? I'd >>prefer the former, but there will be arguments the other way. > >I've been wondering if we should

Re: [HACKERS] jsonb array-style subscripting

2015-08-18 Thread Andrew Dunstan
On 08/18/2015 01:11 AM, Kaare Rasmussen wrote: On 2015-08-17 22:33, Josh Berkus wrote: So, both perl and python do not allow "deep nesting" of assignments. For example: d = { "a" : { } } d["a"]["a1"]["a2"] = 42 Traceback (most recent call last): File "", line 1, in KeyError: 'a1' Not s

Re: [HACKERS] jsonb array-style subscripting

2015-08-18 Thread Andrew Dunstan
On 08/18/2015 01:32 AM, Pavel Stehule wrote: Hi 2015-08-17 21:12 GMT+02:00 Jim Nasby >: On 8/17/15 12:57 PM, Dmitry Dolgov wrote: * is it interesting for the community? We definitely need better ways to manipulate JSON. * is that a

Re: [HACKERS] jsonb array-style subscripting

2015-08-18 Thread Oleg Bartunov
On Mon, Aug 17, 2015 at 11:26 PM, Peter Geoghegan wrote: > On Mon, Aug 17, 2015 at 12:26 PM, Merlin Moncure > wrote: > > ...is a good idea. postgres operators tend to return immutable copies > > of the item they are referring to. > > This patch does not add an operator at all, actually. If feels

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Pavel Stehule
Hi 2015-08-17 21:12 GMT+02:00 Jim Nasby : > On 8/17/15 12:57 PM, Dmitry Dolgov wrote: > >> * is it interesting for the community? >> > > We definitely need better ways to manipulate JSON. > > * is that a good idea to extend the `ArrayRef` for jsonb? If it's >> appropriate, probably we can rename

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Kaare Rasmussen
On 2015-08-17 22:33, Josh Berkus wrote: So, both perl and python do not allow "deep nesting" of assignments. For example: d = { "a" : { } } d["a"]["a1"]["a2"] = 42 Traceback (most recent call last): File "", line 1, in KeyError: 'a1' Not sure I understand what you mean. In Perl you'd do

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Tom Lane
Peter Geoghegan writes: > This patch does not add an operator at all, actually. If feels like > there ought to be an operator, but in fact there is not. The parser is > hard-coded to recognize array-style subscripts, which this uses. > While I'm certainly glad that Dmitry took the time to work on

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Josh Berkus
On 08/17/2015 02:18 PM, Jim Nasby wrote: > On 8/17/15 3:33 PM, Josh Berkus wrote: >> Again, how do we handle missing keys? Just return NULL? or ERROR? I'd >> prefer the former, but there will be arguments the other way. > > I've been wondering if we should add some kind of "strict" JSON. My big

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Tom Lane
Dmitry Dolgov <9erthali...@gmail.com> writes: > * is that a good idea to extend the `ArrayRef` for jsonb? No. Make a new expression node type. (Salesforce did something similar for an internal feature, and it was a disaster both for code modularity and performance. We had to change it to a sepa

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Jim Nasby
On 8/17/15 3:33 PM, Josh Berkus wrote: Again, how do we handle missing keys? Just return NULL? or ERROR? I'd prefer the former, but there will be arguments the other way. I've been wondering if we should add some kind of "strict" JSON. My big concern is throwing an error if you try to provi

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Merlin Moncure
On Mon, Aug 17, 2015 at 2:44 PM, Andrew Dunstan wrote: > > > On 08/17/2015 03:26 PM, Merlin Moncure wrote: >> >> >> I'm not sure if this: >> update test_jsonb_subscript set test_json['a']['a1']['a2'] = 42; >> >> ...is a good idea. postgres operators tend to return immutable copies >> of the item t

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Josh Berkus
On 08/17/2015 10:57 AM, Dmitry Dolgov wrote: > Hi, > > Some time ago the array-style subscripting for the jsonb data type was > discussed in this mailing list. I think it will be quite convenient to > have a such nice syntax to update jsonb objects, so I'm trying to > implement this. I created a p

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Peter Geoghegan
On Mon, Aug 17, 2015 at 12:26 PM, Merlin Moncure wrote: > ...is a good idea. postgres operators tend to return immutable copies > of the item they are referring to. This patch does not add an operator at all, actually. If feels like there ought to be an operator, but in fact there is not. The par

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Andrew Dunstan
On 08/17/2015 03:26 PM, Merlin Moncure wrote: I'm not sure if this: update test_jsonb_subscript set test_json['a']['a1']['a2'] = 42; ...is a good idea. postgres operators tend to return immutable copies of the item they are referring to. In other words, you'd never see a column operator on t

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Peter Geoghegan
On Mon, Aug 17, 2015 at 12:26 PM, Merlin Moncure wrote: > I'm not sure if this: > update test_jsonb_subscript set test_json['a']['a1']['a2'] = 42; > > ...is a good idea. This kind of "targetlist indirection" is already possible with arrays and composite types. -- Peter Geoghegan -- Sent via

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Alvaro Herrera
Dmitry Dolgov wrote: > Some time ago the array-style subscripting for the jsonb data type was > discussed in this mailing list. I think it will be quite convenient to have > a such nice syntax to update jsonb objects, so I'm trying to implement > this. I created a patch, that allows doing somethin

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Merlin Moncure
On Mon, Aug 17, 2015 at 12:57 PM, Dmitry Dolgov <9erthali...@gmail.com> wrote: > Hi, > > Some time ago the array-style subscripting for the jsonb data type was > discussed in this mailing list. I think it will be quite convenient to have > a such nice syntax to update jsonb objects, so I'm trying t

Re: [HACKERS] jsonb array-style subscripting

2015-08-17 Thread Jim Nasby
On 8/17/15 12:57 PM, Dmitry Dolgov wrote: * is it interesting for the community? We definitely need better ways to manipulate JSON. * is that a good idea to extend the `ArrayRef` for jsonb? If it's appropriate, probably we can rename it to `ArrayJsonbRef` of something. * what can be improved

[HACKERS] jsonb array-style subscripting

2015-08-17 Thread Dmitry Dolgov
Hi, Some time ago the array-style subscripting for the jsonb data type was discussed in this mailing list. I think it will be quite convenient to have a such nice syntax to update jsonb objects, so I'm trying to implement this. I created a patch, that allows doing something like this: =# create