Re: Add json_object(text[], json[])?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Add json_object(text[], json[])?
Дата
Msg-id 8657.1571932335@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Add json_object(text[], json[])?  (Paul Jungwirth <pj@illuminatedcomputing.com>)
Ответы Re: Add json_object(text[], json[])?  (Paul A Jungwirth <pj@illuminatedcomputing.com>)
Список pgsql-hackers
Paul Jungwirth <pj@illuminatedcomputing.com> writes:
> I noticed that our existing 2-param json{,b}_object functions take
> text[] for both keys and values, so they are only able to build
> one-layer-deep JSON objects. I'm interested in adding json{,b}_object
> functions that take text[] for the keys and json{,b}[] for the values.
> It would otherwise behave the same as json_object(text[], text[]) (e.g.
> re NULL handling). Does that seem worthwhile to anyone?

I think a potential problem is creation of ambiguity where there was
none before.  I prototyped this as

regression=# create function jsonb_object(text[], jsonb[]) returns jsonb
as 'select jsonb_object($1, $2::text[])' language sql;
CREATE FUNCTION

and immediately got

regression=# explain select jsonb_object('{a}', '{b}');
ERROR:  function jsonb_object(unknown, unknown) is not unique
LINE 1: explain select jsonb_object('{a}', '{b}');
                       ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

which is something that works fine as long as there's only one
jsonb_object().  I'm not sure whether that's a big problem in
practice --- it seems like it will resolve successfully as long
as at least one input isn't an unknown literal.  But it could be
a problem for prepared statements, or clients using APIs that
involve prepared statements under the hood:

regression=# prepare foo as select jsonb_object($1,$2);
ERROR:  function jsonb_object(unknown, unknown) is not unique

Also, as the prototype implementation shows, it's not like you
can't get this functionality today ... you just need to cast
jsonb to text.  Admittedly that's annoying and wasteful.

            regards, tom lane



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

Предыдущее
От: Vik Fearing
Дата:
Сообщение: Re: WIP: System Versioned Temporal Table
Следующее
От: Victor Spirin
Дата:
Сообщение: psql tab-complete