Re: pgsql: Add more SQL/JSON constructor functions

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: pgsql: Add more SQL/JSON constructor functions
Дата
Msg-id CAKFQuwYFaXRcJLb5CkcFHYrwqMCQX2+zPJTQUN1nodHb0DriJw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: pgsql: Add more SQL/JSON constructor functions  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Список pgsql-hackers
On Monday, May 27, 2024, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
On 2024-May-27, Alvaro Herrera wrote:

> > JSON_SERIALIZE()

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?


It’s not a self-evident bug given that this is exactly how casting data to varchar(n) behaves as directed by the SQL Standard.

I'd probably leave the internal consistency and take the opportunity to educate the reader that text is the preferred type in PostgreSQL and, especially here, there is little good reason to use anything else.

David J.

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

Предыдущее
От: "Long Song"
Дата:
Сообщение: Re:[PATCH]A minor improvement to the error-report in SimpleLruWriteAll()
Следующее
От: James Coleman
Дата:
Сообщение: Re: commitfest.postgresql.org is no longer fit for purpose