Re: jsonb array-style subscripting

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: jsonb array-style subscripting
Date: 2015-08-17 20:51:37
Message-ID: CAHyXU0y3r7Yem5OfPDj1QCvyYdvgB_WeqApjxn4kRgh09A8QPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 17, 2015 at 2:44 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> 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 they are referring to. In other words, you'd never see a
>> column operator on the 'left' side of the equals in an update
>> statement. I think you need to look at a function to get the behavior
>> you want:
>>
>> update test_jsonb_subscript set test_json = jsonb_modify(test_json,
>> '[a][a1][a2] = 42');]
>>
>> ...as a hypothetical example. The idea is you need to make a
>> function that provides the ability to make the complete json you want.
>> Update statements always make a copy of the record anyways.
>>
>
>
> Why should jsonb be different from an array? You can assign to an array
> element, using exactly this syntax, except that the index expressions have
> to be integers.
>
> This was discussed at pgcon and generally met with approval. There is some
> demand for it. If Dmitry hadn't done this I would probably have done it
> myself.

Yeah, this all makes sense. I withdraw the statement.

merlin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Verite 2015-08-17 21:07:12 [patch] psql tab completion for grant execute
Previous Message Josh Berkus 2015-08-17 20:33:27 Re: jsonb array-style subscripting