Re: [PATH] Jsonb, insert a new value into an array at arbitrary position

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>
Cc: David Steele <david(at)pgmasters(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATH] Jsonb, insert a new value into an array at arbitrary position
Date: 2016-04-05 15:51:29
Message-ID: 5703DF01.4070005@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 03/31/2016 09:00 AM, Dmitry Dolgov wrote:
> On 31 March 2016 at 17:31, Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com
> <mailto:vitaly(dot)burovoy(at)gmail(dot)com>> wrote:
>
> it is logical to insert new value if "before", then current value,
> then new
> value if "after".
>
>
> Oh, I see now. There is a slightly different logic: `v` is a current
> value and `newval` is a new value.
> So basically we insert a current item in case of "after", then a new
> value (if it's not a delete operation),
> then a current item in case of "before". But I agree, this code can be
> more straightforward. I've attached
> a new version, pls take a look (it contains the same logic that you've
> mentioned).

I haven't been following this thread due to pressure of time, so my
apologies in advance if these comments have already been covered.

I've been asked to look at and comment on the SQL API of the feature. I
think it's basically sound, although there is one thing that's not clear
from the regression tests: what happens if we're inserting into an
object and the key already exists? e.g.:

select jsonb_insert('{"a": {"b": "value"}}', '{a, b}', '"new_value"');

I think this should be forbidden, i.e. the function shouldn't ever
overwrite an existing value. If that's not handled it should be, and
either way there should be a regression test for it.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Petr Jelinek 2016-04-05 15:52:46 Re: Sequence Access Method WIP
Previous Message Andres Freund 2016-04-05 15:30:21 Re: Move PinBuffer and UnpinBuffer to atomics