@@ -135,6 +135,8 @@ static Node *transformJsonIsPredicate(ParseState *pstate, JsonIsPredicate *p);
135135static Node * transformJsonFuncExpr (ParseState * pstate , JsonFuncExpr * p );
136136static Node * transformJsonValueExpr (ParseState * pstate , JsonValueExpr * jve );
137137static Node * transformJsonScalarExpr (ParseState * pstate , JsonScalarExpr * expr );
138+ static Node * transformJsonSerializeExpr (ParseState * pstate ,
139+ JsonSerializeExpr * expr );
138140static Node * make_row_comparison_op (ParseState * pstate , List * opname ,
139141 List * largs , List * rargs , int location );
140142static Node * make_row_distinct_op (ParseState * pstate , List * opname ,
@@ -419,6 +421,10 @@ transformExprRecurse(ParseState *pstate, Node *expr)
419421 result = transformJsonScalarExpr (pstate , (JsonScalarExpr * ) expr );
420422 break ;
421423
424+ case T_JsonSerializeExpr :
425+ result = transformJsonSerializeExpr (pstate , (JsonSerializeExpr * ) expr );
426+ break ;
427+
422428 default :
423429 /* should not reach here */
424430 elog (ERROR , "unrecognized node type: %d" , (int ) nodeTag (expr ));
@@ -4911,3 +4917,27 @@ transformJsonScalarExpr(ParseState *pstate, JsonScalarExpr *jsexpr)
49114917 return makeJsonConstructorExpr (pstate , JSCTOR_JSON_SCALAR , list_make1 (arg ), NULL ,
49124918 returning , false, false, jsexpr -> location );
49134919}
4920+
4921+ /*
4922+ * Transform a JSON_SERIALIZE() expression.
4923+ */
4924+ static Node *
4925+ transformJsonSerializeExpr (ParseState * pstate , JsonSerializeExpr * expr )
4926+ {
4927+ Node * arg = transformJsonValueExpr (pstate , expr -> expr );
4928+ JsonReturning * returning ;
4929+
4930+ if (expr -> output )
4931+ returning = transformJsonOutput (pstate , expr -> output , true);
4932+ else
4933+ {
4934+ /* RETURNING TEXT FORMAT JSON is by default */
4935+ returning = makeNode (JsonReturning );
4936+ returning -> format = makeJsonFormat (JS_FORMAT_JSON , JS_ENC_DEFAULT , -1 );
4937+ returning -> typid = TEXTOID ;
4938+ returning -> typmod = -1 ;
4939+ }
4940+
4941+ return makeJsonCtorExpr (pstate , JSCTOR_JSON_SERIALIZE , list_make1 (arg ),
4942+ NULL , returning , false, false, expr -> location );
4943+ }
0 commit comments