From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Joel Jacobson <joel(at)compiler(dot)org> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Avoid undesired flattening of jsonb arrays? |
Date: | 2020-12-18 15:33:51 |
Message-ID: | CAKFQuwYAjzoDtUdXz03K-Cs8UDG9TKkdQLRAWAxFc2kGwMr0_A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Dec 18, 2020 at 8:24 AM Joel Jacobson <joel(at)compiler(dot)org> wrote:
> The || operator for the jsonb type has a surprising behaviour.
>
> Instead of appending the right operand "as is" to the left operand,
> it has a magic behaviour if the right operand is an array,
> in which case it will append the items of the array,
> instead of appending the array itself as a single value.
>
>
It's not magic, and it is documented clearly.
I'll agree that the description could discuss the case explicitly, and the
array||scalar case could be added to the examples.
> Suggestions welcome if there is a better way to solve this problem.
>
>
As you are writing literals just put an array in the to-be-merged array.
select '["a","b"]'::jsonb || '[["c","d"]]'::jsonb
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Lars Vonk | 2020-12-18 15:42:12 | Missing rows after migrating from postgres 11 to 12 with logical replication |
Previous Message | Joel Jacobson | 2020-12-18 15:23:40 | Avoid undesired flattening of jsonb arrays? |