From f4fb45d15c59d7add2e1b81a9d477d0119a9691a Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Thu, 3 Mar 2022 13:02:10 -0500 Subject: SQL/JSON constructors This patch introduces the SQL/JSON standard constructors for JSON: JSON() JSON_ARRAY() JSON_ARRAYAGG() JSON_OBJECT() JSON_OBJECTAGG() For the most part these functions provide facilities that mimic existing json/jsonb functions. However, they also offer some useful additional functionality. In addition to text input, the JSON() function accepts bytea input, which it will decode and constuct a json value from. The other functions provide useful options for handling duplicate keys and null values. This series of patches will be followed by a consolidated documentation patch. Nikita Glukhov Reviewers have included (in no particular order) Andres Freund, Alexander Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu, Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby. Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru --- src/backend/nodes/readfuncs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/backend/nodes/readfuncs.c') diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 6f398cdc15b..e0b3ad1ed20 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -1434,6 +1434,26 @@ _readJsonValueExpr(void) READ_DONE(); } +/* + * _readJsonConstructorExpr + */ +static JsonConstructorExpr * +_readJsonConstructorExpr(void) +{ + READ_LOCALS(JsonConstructorExpr); + + READ_NODE_FIELD(args); + READ_NODE_FIELD(func); + READ_NODE_FIELD(coercion); + READ_INT_FIELD(type); + READ_NODE_FIELD(returning); + READ_BOOL_FIELD(unique); + READ_BOOL_FIELD(absent_on_null); + READ_LOCATION_FIELD(location); + + READ_DONE(); +} + /* * Stuff from pathnodes.h. * @@ -3025,6 +3045,8 @@ parseNodeString(void) return_value = _readJsonReturning(); else if (MATCH("JSONVALUEEXPR", 13)) return_value = _readJsonValueExpr(); + else if (MATCH("JSONCTOREXPR", 12)) + return_value = _readJsonConstructorExpr(); else { elog(ERROR, "badly formatted node string \"%.32s\"...", token); -- cgit v1.2.3