Re: jsonb_delete with arrays

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: jsonb_delete with arrays
Date: 2017-01-18 20:42:06
Message-ID: CABUevEz4eCS5upL4NeZ5oZrSCOdgBk7bYmTNK7R1_a1yYj-qqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 18, 2017 at 5:49 AM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
wrote:

> On Tue, Jan 17, 2017 at 8:45 PM, Magnus Hagander <magnus(at)hagander(dot)net>
> wrote:
> > On Tue, Jan 17, 2017 at 8:25 AM, Michael Paquier <
> michael(dot)paquier(at)gmail(dot)com>
> > wrote:
> >> On Sun, Dec 18, 2016 at 1:27 AM, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> >> wrote:
> >> > * use variadic arguments for `jsonb_delete_array`. For rare cases,
> when
> >> > someone decides to use this function directly instead of corresponding
> >> > operator. It will be more consistent with `jsonb_delete` from my point
> >> > of
> >> > view, because it's transition from `jsonb_delete(data, 'key')` to
> >> > `jsonb_delete(data, 'key1', 'key2')` is more smooth, than to
> >> > `jsonb_delete(data, '{key1, key2}')`.
> >>
> >> That's a good idea.
> >
> > I can see the point of that. In the particular usecase I built it for
> > originally though, the list of keys came from the application, in which
> case
> > binding them as an array was a lot more efficient (so as not to require a
> > whole lot of different prepared statements, one for each number of
> > parameters). But that should be workaround-able using the VARIADIC
> keyword
> > in the caller. Or by just using the operator.
>
> Yes that should be enough:
> =# select jsonb_delete('{"a":1 , "b":2, "c":3}', 'a', 'b', 'c');
> jsonb_delete
> --------------
> {}
> (1 row)
> =# select '{"a":1 , "b":2, "c":3}'::jsonb - '{a,b}'::text[];
> ?column?
> ----------
> {"c": 3}
> (1 row)
> That's a nice bonus, perhaps that's not worth documenting as most
> users will likely care only about the operator.
>
> >> > I've attached a patch with these modifications. What do you think?
> >>
> >> Looking at both patches proposed, documentation is still missing in
> >> the list of jsonb operators as '-' is missing for arrays. I am marking
> >> this patch as waiting on author for now.
> >
> > Added in updated patch. Do you see that as enough, or do we need it in
> some
> > more places in the docs as well?
>
> I am not seeing other places to update, thanks.
>
> Another victim of 352a24a... Your patch is failing to apply because
> now the headers of the functions is generated automatically. And the
> OIDs have been taken recently. I have fixed that to test your patch,
> the result is attached. The patch is marked as ready for committer.
>

Thanks! I had already rebased it, so I pushed that version (picked
different oids).

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2017-01-18 20:43:30 Re: Re: Clarifying "server starting" messaging in pg_ctl start without --wait
Previous Message Robert Haas 2017-01-18 20:37:23 Re: Re: Clarifying "server starting" messaging in pg_ctl start without --wait