Re: Weird special case in jsonb_concat()

Поиск
Список
Период
Сортировка
От Joel Jacobson
Тема Re: Weird special case in jsonb_concat()
Дата
Msg-id 0b1c7b60-85ce-438d-b196-0f48b637e0ef@www.fastmail.com
обсуждение исходный текст
Ответ на Re: Weird special case in jsonb_concat()  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Weird special case in jsonb_concat()  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Sat, Dec 19, 2020, at 21:35, Tom Lane wrote:
>Here is a proposed patch for that.

I've tested the patch and "All 202 tests passed".

In addition, I've tested it on a json intensive project,
which passes all its own tests.

I haven't studied the jsonfuncs.c code in detail,
but the new code looks much cleaner, nice.

>This also addresses the inadequate documentation that was the
>original complaint.

Looks good.

In addition, to the user wondering how to append a json array-value "as is",
I think it would be useful to provide an example on how to do this
in the documentation.

I think there is a risk users will attempt much more fragile
hacks to achieve this, if we don't provide guidance
in the documentation.

Suggestion:

         <literal>'["a", "b"]'::jsonb || '["a", "d"]'::jsonb</literal>
         <returnvalue>["a", "b", "a", "d"]</returnvalue>
        </para>
+       <para>
+        <literal>'["a", "b"]'::jsonb || jsonb_build_array('["a", "d"]'::jsonb)</literal>
+        <returnvalue>["a", "b", ["a", "d"]]</returnvalue>
+       </para>
        <para>
         <literal>'{"a": "b"}'::jsonb || '{"c": "d"}'::jsonb</literal>
         <returnvalue>{"a": "b", "c": "d"}</returnvalue>

> Thoughts?  Should we back-patch this?  The existing behavior
> seems to me to be inconsistent enough to be arguably a bug,
> but we've not had field complaints saying "this should work".

+1 back-patch, I think it's a bug.

Best regards,

Joel

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_preadv() and pg_pwritev()
Следующее
От: Alexander Lakhin
Дата:
Сообщение: Re: how to use valgrind for TAP tests