Hi,

One more consequence of this bug that I think matters for the
back-patching question. Nikhil wrote upthread that no back-patch is
intended. The bug doesn't just produce a confusing result: the result is
a text value whose bytes are taken from the jsonb header, so it can be
invalidly encoded, and it can be stored. In a UTF8 database, on 18.6:

    CREATE TABLE t (s text);
    INSERT INTO t SELECT json_serialize(jsonb_agg(g))
      FROM generate_series(1, 200) g;
    SELECT encode(s::bytea, 'hex') FROM t;     -- c8
    SELECT convert_to(s, 'UTF8') FROM t;
    ERROR:  invalid byte sequence for encoding "UTF8": 0xc8

pg_dump of such a table succeeds, but restoring the dump fails:

    ERROR:  invalid byte sequence for encoding "UTF8": 0xc8 0x0a

and the table ends up empty. With v3 applied to master, the same INSERT stores 
the correct
892-byte text. Given that, I think the fix should be back-patched to 17,
where JSON_SERIALIZE() was added (REL_17_STABLE has the same code).

Also, in the original pgsql-bugs thread, Shihao Zhong has since posted
another patch for the same bug:
https://postgr.es/m/[email protected]
so it's probably worth closing both together.

--
Ilya Staroverov

Reply via email to