Re: pgsql: Add more SQL/JSON constructor functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: pgsql: Add more SQL/JSON constructor functions
Дата
Msg-id 3189.1717001075@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: pgsql: Add more SQL/JSON constructor functions  (Amit Langote <amitlangote09@gmail.com>)
Ответы Re: pgsql: Add more SQL/JSON constructor functions
Список pgsql-hackers
Amit Langote <amitlangote09@gmail.com> writes:
> On Mon, May 27, 2024 at 7:10 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>> On 2024-May-27, Alvaro Herrera wrote:
>> I just noticed this behavior, which looks like a bug to me:
>>
>> select json_serialize('{"a":1, "a":2}' returning varchar(5));
>> json_serialize
>> ────────────────
>> {"a":
>>
>> I think this function should throw an error if the destination type
>> doesn't have room for the output json.  Otherwise, what good is the
>> serialization function?

> This behavior comes from using COERCE_EXPLICIT_CAST when creating the
> coercion expression to convert json_*() functions' argument to the
> RETURNING type.

Yeah, I too think this is a cast, and truncation is the spec-defined
behavior for casting to varchar with a specific length limit.  I see
little reason that this should work differently from

select json_serialize('{"a":1, "a":2}' returning text)::varchar(5);
 json_serialize
----------------
 {"a":
(1 row)


            regards, tom lane



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

Предыдущее
От: vignesh C
Дата:
Сообщение: Re: 001_rep_changes.pl fails due to publisher stuck on shutdown
Следующее
От: Noah Misch
Дата:
Сообщение: Re: Remove last traces of HPPA support