On Monday, May 27, 2024, Alvaro Herrera <alvhe...@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.