@@ -220,6 +220,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
220220 JoinType jtype;
221221 DropBehavior dbehavior;
222222 OnCommitAction oncommit;
223+ JsonFormat jsformat;
223224 List *list;
224225 Node *node;
225226 Value *value;
@@ -599,6 +600,15 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
599600%type <list> hash_partbound
600601%type <defelt> hash_partbound_elem
601602
603+ %type <node> json_value_expr
604+ json_output_clause_opt
605+
606+ %type <ival> json_encoding
607+ json_encoding_clause_opt
608+
609+ %type <jsformat> json_format_clause_opt
610+ json_representation
611+
602612/*
603613 * Non-keyword token types. These are hard-wired into the "flex" lexer.
604614 * They must be listed first so that their numeric codes do not depend on
@@ -650,7 +660,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
650660 EXTENSION EXTERNAL EXTRACT
651661
652662 FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
653- FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
663+ FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
654664
655665 GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
656666
@@ -661,7 +671,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
661671 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
662672 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
663673
664- JOIN
674+ JOIN JSON
665675
666676 KEY
667677
@@ -729,9 +739,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
729739 */
730740%token NOT_LA NULLS_LA WITH_LA
731741
732-
733742/* Precedence: lowest to highest */
734743%nonassoc SET /* see relation_expr_opt_alias */
744+ %right FORMAT
735745%left UNION EXCEPT
736746%left INTERSECT
737747%left OR
@@ -14635,6 +14645,58 @@ opt_asymmetric: ASYMMETRIC
1463514645 | /* EMPTY*/
1463614646 ;
1463714647
14648+ /* SQL/JSON support */
14649+
14650+ json_value_expr:
14651+ a_expr json_format_clause_opt
14652+ {
14653+ $$ = (Node *) makeJsonValueExpr ((Expr *) $1 , $2 );
14654+ }
14655+ ;
14656+
14657+ json_format_clause_opt:
14658+ FORMAT json_representation
14659+ {
14660+ $$ = $2 ;
14661+ $$.location = @1 ;
14662+ }
14663+ | /* EMPTY */
14664+ {
14665+ $$.type = JS_FORMAT_DEFAULT;
14666+ $$.encoding = JS_ENC_DEFAULT;
14667+ $$.location = -1 ;
14668+ }
14669+ ;
14670+
14671+ json_representation:
14672+ JSON json_encoding_clause_opt
14673+ {
14674+ $$.type = JS_FORMAT_JSON;
14675+ $$.encoding = $2 ;
14676+ $$.location = @1 ;
14677+ }
14678+ /* | implementation_defined_JSON_representation_option (BSON, AVRO etc) */
14679+ ;
14680+
14681+ json_encoding_clause_opt:
14682+ ENCODING json_encoding { $$ = $2 ; }
14683+ | /* EMPTY */ { $$ = JS_ENC_DEFAULT; }
14684+ ;
14685+
14686+ json_encoding:
14687+ name { $$ = makeJsonEncoding ($1 ); }
14688+ ;
14689+
14690+ json_output_clause_opt:
14691+ RETURNING Typename json_format_clause_opt
14692+ {
14693+ JsonOutput *n = makeNode (JsonOutput);
14694+ n->typeName = $2 ;
14695+ n->returning .format = $3 ;
14696+ $$ = (Node *) n;
14697+ }
14698+ | /* EMPTY */ { $$ = NULL ; }
14699+ ;
1463814700
1463914701/* ****************************************************************************
1464014702 *
@@ -15113,6 +15175,7 @@ unreserved_keyword:
1511315175 | FIRST_P
1511415176 | FOLLOWING
1511515177 | FORCE
15178+ | FORMAT
1511615179 | FORWARD
1511715180 | FUNCTION
1511815181 | FUNCTIONS
@@ -15144,6 +15207,7 @@ unreserved_keyword:
1514415207 | INSTEAD
1514515208 | INVOKER
1514615209 | ISOLATION
15210+ | JSON
1514715211 | KEY
1514815212 | LABEL
1514915213 | LANGUAGE
0 commit comments