BUG #14364: json_populate_record doesn't accept JSON arrays

Started by Joerg Sonnenbergerover 9 years ago2 messagesbugs
Jump to latest

The following bug has been logged on the website:

Bug reference: 14364
Logged by: Jörg Sonnenberger
Email address: joerg@bec.de
PostgreSQL version: 9.4.9
Operating system: Linux
Description:

json_populate_record expects arrays in fields using the PG array literal
syntax, it doesn't support JSON arrays. This is highly annoying as the JSON
output functions like row_to_json will create JSON arrays, so round-trip
fidelity is lost.

Small example:

CREATE TEMPORARY TABLE test (a int, b int[]);
SELECT json_populate_record(NULL::test, '{"a": 5, "b": [1,2]}');

gives:

ERROR: malformed array literal: "[1,2]"
DETAIL: Missing "]" after array dimensions.

But

SELECT json_populate_record(NULL::test, '{"a": 5, "b": "{1,2}"}');

is accepted. Accepting JSON arrays directly would be backwards-compatible.

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Joerg Sonnenberger (#1)
Re: BUG #14364: json_populate_record doesn't accept JSON arrays

joerg@bec.de writes:

json_populate_record expects arrays in fields using the PG array literal
syntax, it doesn't support JSON arrays. This is highly annoying as the JSON
output functions like row_to_json will create JSON arrays, so round-trip
fidelity is lost.

Yeah, this has come up before; one recent discussion is at
/messages/by-id/CAPpdape1SieipHCyZVbgtkb5NaD00FKGjiEoqfYj=Pi+9ffisg@mail.gmail.com

Basically, these functions weren't built to process nested structures
recursively, and making them do so is a bit more work than anyone has
seen fit to put into them yet. We'd accept a patch ...

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs