Skip to content

Commit 73f6e68

Browse files
authored
feat(postgresql): introduce change in postgres commit 7081ac (#19)
* feat: support postgresql16 json constructor feature * feat: commit 7081ac46ace8c459966174400b53418683c9fe5c * fix: fix
1 parent 80e1ea5 commit 73f6e68

11 files changed

+25539
-18956
lines changed

postgresql/PostgreSQLLexer.g4

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,81 @@ WITH
539539
: 'WITH'
540540
;
541541

542+
JSON_OBJECT
543+
: 'JSON_OBJECT'
544+
;
545+
546+
JSON_ARRAY
547+
: 'JSON_ARRAY'
548+
;
549+
550+
JSON
551+
: 'JSON'
552+
;
553+
554+
JSON_SCALAR
555+
: 'JSON_SCALAR'
556+
;
557+
558+
JSON_SERIALIZE
559+
: 'JSON_SERIALIZE'
560+
;
561+
562+
MERGE_ACTION
563+
: 'MERGE_ACTION'
564+
;
565+
566+
JSON_QUERY
567+
: 'JSON_QUERY'
568+
;
569+
570+
JSON_EXISTS
571+
: 'JSON_EXISTS'
572+
;
573+
574+
JSON_VALUE
575+
: 'JSON_VALUE'
576+
;
577+
578+
EMPTY
579+
: 'EMPTY'
580+
;
581+
582+
KEEP
583+
: 'KEEP'
584+
;
585+
586+
OMIT
587+
: 'OMIT'
588+
;
589+
590+
SCALAR
591+
: 'SCALAR'
592+
;
593+
594+
STRING
595+
: 'STRING'
596+
;
597+
598+
CONDITIONAL
599+
: 'CONDITIONAL'
600+
;
601+
602+
UNCONDITIONAL
603+
: 'UNCONDITIONAL'
604+
;
605+
606+
KEYS
607+
: 'KEYS'
608+
;
609+
610+
ABSENT
611+
: 'ABSENT'
612+
;
613+
614+
QUOTES
615+
: 'QUOTES'
616+
;
542617
//
543618

544619
// reserved keywords (can be function or type)
@@ -2713,6 +2788,14 @@ CASE_INSENSITIVE
27132788
: 'CASE_INSENSITIVE'
27142789
;
27152790

2791+
JSON_ARRAYAGG
2792+
: 'JSON_ARRAYAGG'
2793+
;
2794+
2795+
JSON_OBJECTAGG
2796+
: 'JSON_OBJECTAGG'
2797+
;
2798+
27162799
Identifier
27172800
: IdentifierStartChar IdentifierChar*
27182801
;

postgresql/PostgreSQLParser.g4

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,12 +3558,27 @@ func_application
35583558

35593559
func_expr
35603560
: func_application within_group_clause? filter_clause? over_clause?
3561+
| json_aggregate_func filter_clause? over_clause?
35613562
| func_expr_common_subexpr
35623563
;
35633564

35643565
func_expr_windowless
35653566
: func_application
35663567
| func_expr_common_subexpr
3568+
| json_aggregate_func
3569+
;
3570+
3571+
json_aggregate_func
3572+
: JSON_OBJECTAGG OPEN_PAREN json_name_and_value json_object_constructor_null_clause? json_key_uniqueness_constraint? json_output_clause? CLOSE_PAREN
3573+
| JSON_ARRAYAGG OPEN_PAREN json_value_expr json_array_aggregate_order_by_clause? json_array_constructor_null_clause? json_output_clause? CLOSE_PAREN
3574+
;
3575+
3576+
json_output_clause
3577+
: RETURNING typename json_format_clause?
3578+
;
3579+
3580+
json_array_aggregate_order_by_clause
3581+
: ORDER BY sortby_list
35673582
;
35683583

35693584
func_expr_common_subexpr
@@ -3599,6 +3614,125 @@ func_expr_common_subexpr
35993614
| XMLPI OPEN_PAREN NAME_P collabel (COMMA a_expr)? CLOSE_PAREN
36003615
| XMLROOT OPEN_PAREN XML_P a_expr COMMA xml_root_version opt_xml_root_standalone? CLOSE_PAREN
36013616
| XMLSERIALIZE OPEN_PAREN document_or_content a_expr AS simpletypename CLOSE_PAREN
3617+
| JSON_OBJECT '(' func_arg_list ')'
3618+
| JSON_OBJECT '(' json_name_and_value_list json_object_constructor_null_clause? json_key_uniqueness_constraint? json_returning_clause? ')'
3619+
| JSON_OBJECT '(' json_returning_clause? ')'
3620+
| JSON_ARRAY '(' json_value_expr_list json_array_constructor_null_clause? json_returning_clause? ')'
3621+
| JSON_ARRAY '(' select_no_parens json_format_clause_opt? json_returning_clause? ')'
3622+
| JSON_ARRAY '(' json_returning_clause? ')'
3623+
| JSON '(' json_value_expr json_key_uniqueness_constraint? ')'
3624+
| JSON_SCALAR '(' a_expr ')'
3625+
| JSON_SERIALIZE '(' json_value_expr json_returning_clause? ')'
3626+
| MERGE_ACTION '(' ')'
3627+
| JSON_QUERY '('
3628+
json_value_expr ',' a_expr json_passing_clause?
3629+
json_returning_clause?
3630+
json_wrapper_behavior
3631+
json_quotes_clause?
3632+
json_behavior_clause?
3633+
')'
3634+
| JSON_EXISTS '('
3635+
json_value_expr ',' a_expr json_passing_clause?
3636+
json_on_error_clause?
3637+
')'
3638+
| JSON_VALUE '('
3639+
json_value_expr ',' a_expr json_passing_clause?
3640+
json_returning_clause?
3641+
json_behavior_clause?
3642+
')'
3643+
;
3644+
3645+
json_on_error_clause
3646+
: json_behavior ON ERROR
3647+
;
3648+
3649+
json_behavior_clause
3650+
: json_behavior ON EMPTY
3651+
| json_behavior ON ERROR
3652+
| json_behavior ON EMPTY json_behavior ON ERROR
3653+
;
3654+
3655+
json_behavior
3656+
: DEFAULT a_expr
3657+
| json_behavior_type
3658+
;
3659+
3660+
json_behavior_type
3661+
: ERROR
3662+
| NULL_P
3663+
| TRUE_P
3664+
| FALSE_P
3665+
| UNKNOWN
3666+
| EMPTY ARRAY
3667+
| EMPTY OBJECT_P
3668+
| EMPTY
3669+
;
3670+
3671+
json_quotes_clause
3672+
: (KEEP | OMIT) QUOTES (ON SCALAR STRING)
3673+
;
3674+
3675+
json_wrapper_behavior
3676+
: WITHOUT ARRAY? WRAPPER
3677+
| WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY? WRAPPER
3678+
;
3679+
3680+
json_passing_clause
3681+
: PASSING json_arguments
3682+
;
3683+
3684+
json_arguments
3685+
: json_argument (COMMA json_argument)*
3686+
;
3687+
3688+
json_argument
3689+
: json_value_expr AS collabel
3690+
;
3691+
3692+
json_format_clause_opt
3693+
: FORMAT JSON ENCODING name
3694+
| FORMAT JSON
3695+
;
3696+
3697+
json_value_expr_list
3698+
: json_value_expr (COMMA json_value_expr)*
3699+
;
3700+
3701+
json_returning_clause
3702+
: RETURNING typename json_format_clause?
3703+
;
3704+
3705+
json_key_uniqueness_constraint
3706+
: WITH UNIQUE KEYS?
3707+
| WITHOUT UNIQUE KEYS?
3708+
;
3709+
3710+
json_array_constructor_null_clause
3711+
: NULL_P ON NULL_P
3712+
| ABSENT ON NULL_P
3713+
;
3714+
3715+
json_object_constructor_null_clause
3716+
: NULL_P ON NULL_P
3717+
| ABSENT ON NULL_P
3718+
;
3719+
3720+
json_name_and_value_list
3721+
: json_name_and_value (COMMA json_name_and_value)*
3722+
;
3723+
3724+
json_name_and_value
3725+
: c_expr VALUE_P json_value_expr
3726+
| a_expr COLON json_value_expr
3727+
;
3728+
3729+
json_value_expr
3730+
: a_expr json_format_clause?
3731+
;
3732+
3733+
json_format_clause
3734+
: FORMAT JSON ENCODING name
3735+
| FORMAT JSON
36023736
;
36033737

36043738
xml_root_version
@@ -4056,6 +4190,7 @@ plsqlidentifier
40564190

40574191
unreserved_keyword
40584192
: ABORT_P
4193+
| ABSENT
40594194
| ABSOLUTE_P
40604195
| ACCESS
40614196
| ACTION
@@ -4147,6 +4282,7 @@ unreserved_keyword
41474282
| FIRST_P
41484283
| FOLLOWING
41494284
| FORCE
4285+
| FORMAT
41504286
| FORWARD
41514287
| FUNCTION
41524288
| FUNCTIONS
@@ -4178,7 +4314,9 @@ unreserved_keyword
41784314
| INSTEAD
41794315
| INVOKER
41804316
| ISOLATION
4317+
| JSON
41814318
| KEY
4319+
| KEYS
41824320
| LABEL
41834321
| LANGUAGE
41844322
| LARGE_P
@@ -4307,6 +4445,7 @@ unreserved_keyword
43074445
| STORAGE
43084446
| STORED
43094447
| STRICT_P
4448+
| STRING
43104449
| STRIP_P
43114450
| SUBSCRIPTION
43124451
| SUPPORT
@@ -4376,6 +4515,10 @@ col_name_keyword
43764515
| INT_P
43774516
| INTEGER
43784517
| INTERVAL
4518+
| JSON_ARRAY
4519+
| JSON_ARRAYAGG
4520+
| JSON_OBJECT
4521+
| JSON_OBJECTAGG
43794522
| LEAST
43804523
| NATIONAL
43814524
| NCHAR

postgresql/checkpoint.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Last commit for gram.y at https://github.com/postgres/postgres/blob/master/src/backend/parser/gram.y
2+
7081ac46ace8c459966174400b53418683c9fe5c

0 commit comments

Comments
 (0)