From f79b803dcc98d707450e158db3638dc67ff8380b Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Thu, 3 Mar 2022 13:00:49 -0500 Subject: Common SQL/JSON clauses This introduces some of the building blocks used by the SQL/JSON constructor and query functions. Specifically, it provides node executor and grammar support for the FORMAT JSON [ENCODING foo] clause, and values decorated with it, and for the RETURNING clause. The following SQL/JSON patches will leverage these. Nikita Glukhov (who probably deserves an award for perseverance). 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 | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/backend/nodes/readfuncs.c') diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 3f68f7c18d9..6f398cdc15b 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -1389,6 +1389,51 @@ _readOnConflictExpr(void) READ_DONE(); } +/* + * _readJsonFormat + */ +static JsonFormat * +_readJsonFormat(void) +{ + READ_LOCALS(JsonFormat); + + READ_ENUM_FIELD(format_type, JsonFormatType); + READ_ENUM_FIELD(encoding, JsonEncoding); + READ_LOCATION_FIELD(location); + + READ_DONE(); +} + +/* + * _readJsonReturning + */ +static JsonReturning * +_readJsonReturning(void) +{ + READ_LOCALS(JsonReturning); + + READ_NODE_FIELD(format); + READ_OID_FIELD(typid); + READ_INT_FIELD(typmod); + + READ_DONE(); +} + +/* + * _readJsonValueExpr + */ +static JsonValueExpr * +_readJsonValueExpr(void) +{ + READ_LOCALS(JsonValueExpr); + + READ_NODE_FIELD(raw_expr); + READ_NODE_FIELD(formatted_expr); + READ_NODE_FIELD(format); + + READ_DONE(); +} + /* * Stuff from pathnodes.h. * @@ -2974,6 +3019,12 @@ parseNodeString(void) return_value = _readPartitionBoundSpec(); else if (MATCH("PARTITIONRANGEDATUM", 19)) return_value = _readPartitionRangeDatum(); + else if (MATCH("JSONFORMAT", 10)) + return_value = _readJsonFormat(); + else if (MATCH("JSONRETURNING", 13)) + return_value = _readJsonReturning(); + else if (MATCH("JSONVALUEEXPR", 13)) + return_value = _readJsonValueExpr(); else { elog(ERROR, "badly formatted node string \"%.32s\"...", token); -- cgit v1.2.3