From: Joel Jacobson <joel@compiler.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Avoid undesired flattening of jsonb arrays?
Date: Fri, 18 Dec 2020 18:03:16 +0100
Message-ID: <358bd217-0891-4f9f-b82f-082bf139191d@www.fastmail.com> (raw)
In-Reply-To: <160622.1608308434@sss.pgh.pa.us>
References: <0d72b76d-ca2b-4263-8888-d6dfca861c51@www.fastmail.com>
<CAKFQuwYAjzoDtUdXz03K-Cs8UDG9TKkdQLRAWAxFc2kGwMr0_A@mail.gmail.com>
<160622.1608308434@sss.pgh.pa.us>
The following nicer work-around was suggested to me by Andreas Karlsson:
- jsonb_insert(x.jsonb_array,'{-1}',next_item.item,TRUE)
+ x.jsonb_array || jsonb_build_array(next_item.item)
On Fri, Dec 18, 2020, at 17:20, Tom Lane wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > I'll agree that the description could discuss the case explicitly, and the
> > array||scalar case could be added to the examples.
>
> Yeah, the documentation completely fails to explain what happens
> when the inputs aren't two arrays or two objects. I'd kind of assumed
> that that's an error, but it isn't. Some experimentation indicates
> that the behavior in all cases except two objects is to convert any
> non-array input to a one-element array, reducing the situation to the
> two-array case.
>
> regards, tom lane
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: joel@compiler.org, tgl@sss.pgh.pa.us, david.g.johnston@gmail.com
Subject: Re: Avoid undesired flattening of jsonb arrays?
In-Reply-To: <358bd217-0891-4f9f-b82f-082bf139191d@www.fastmail.com>
References: <0d72b76d-ca2b-4263-8888-d6dfca861c51@www.fastmail.com> <CAKFQuwYAjzoDtUdXz03K-Cs8UDG9TKkdQLRAWAxFc2kGwMr0_A@mail.gmail.com> <160622.1608308434@sss.pgh.pa.us> <358bd217-0891-4f9f-b82f-082bf139191d@www.fastmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox