-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
PostgreSQLParser.g4
5462 lines (4539 loc) · 109 KB
/
PostgreSQLParser.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
PostgreSQL grammar.
The MIT License (MIT).
Copyright (c) 2021-2023, Oleksii Kovalov ([email protected]).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
parser grammar PostgreSQLParser;
options {
tokenVocab = PostgreSQLLexer;
superClass = PostgreSQLParserBase;
}
// Insert here @header for C++ parser.
root
: stmtblock EOF
;
stmtblock
: stmtmulti
;
stmtmulti
: stmt? (SEMI stmt?)*
;
stmt
: altereventtrigstmt
| altercollationstmt
| alterdatabasestmt
| alterdatabasesetstmt
| alterdefaultprivilegesstmt
| alterdomainstmt
| alterenumstmt
| alterextensionstmt
| alterextensioncontentsstmt
| alterfdwstmt
| alterforeignserverstmt
| alterfunctionstmt
| altergroupstmt
| alterobjectdependsstmt
| alterobjectschemastmt
| alterownerstmt
| alteroperatorstmt
| altertypestmt
| alterpolicystmt
| alterseqstmt
| altersystemstmt
| altertablestmt
| altertblspcstmt
| altercompositetypestmt
| alterpublicationstmt
| alterrolesetstmt
| alterrolestmt
| altersubscriptionstmt
| alterstatsstmt
| altertsconfigurationstmt
| altertsdictionarystmt
| alterusermappingstmt
| analyzestmt
| callstmt
| checkpointstmt
| closeportalstmt
| clusterstmt
| commentstmt
| constraintssetstmt
| copystmt
| createamstmt
| createasstmt
| createassertionstmt
| createcaststmt
| createconversionstmt
| createdomainstmt
| createextensionstmt
| createfdwstmt
| createforeignserverstmt
| createforeigntablestmt
| createfunctionstmt
| creategroupstmt
| creatematviewstmt
| createopclassstmt
| createopfamilystmt
| createpublicationstmt
| alteropfamilystmt
| createpolicystmt
| createplangstmt
| createschemastmt
| createseqstmt
| createstmt
| createsubscriptionstmt
| createstatsstmt
| createtablespacestmt
| createtransformstmt
| createtrigstmt
| createeventtrigstmt
| createrolestmt
| createuserstmt
| createusermappingstmt
| createdbstmt
| deallocatestmt
| declarecursorstmt
| definestmt
| deletestmt
| discardstmt
| dostmt
| dropcaststmt
| dropopclassstmt
| dropopfamilystmt
| dropownedstmt
| dropstmt
| dropsubscriptionstmt
| droptablespacestmt
| droptransformstmt
| droprolestmt
| dropusermappingstmt
| dropdbstmt
| executestmt
| explainstmt
| fetchstmt
| grantstmt
| grantrolestmt
| importforeignschemastmt
| indexstmt
| insertstmt
| mergestmt
| listenstmt
| refreshmatviewstmt
| loadstmt
| lockstmt
| notifystmt
| preparestmt
| reassignownedstmt
| reindexstmt
| removeaggrstmt
| removefuncstmt
| removeoperstmt
| renamestmt
| revokestmt
| revokerolestmt
| rulestmt
| seclabelstmt
| selectstmt
| transactionstmt
| truncatestmt
| unlistenstmt
| updatestmt
| vacuumstmt
| variableresetstmt
| variablesetstmt
| variableshowstmt
| viewstmt
;
callstmt
: CALL func_application
;
createrolestmt
: CREATE ROLE roleid with_? optrolelist
;
with_
: WITH
//| WITH_LA
;
optrolelist
: createoptroleelem*
;
alteroptrolelist
: alteroptroleelem*
;
alteroptroleelem
: PASSWORD (sconst | NULL_P)
| (ENCRYPTED | UNENCRYPTED) PASSWORD sconst
| INHERIT
| CONNECTION LIMIT signediconst
| VALID UNTIL sconst
| USER role_list
| identifier
;
createoptroleelem
: alteroptroleelem
| SYSID iconst
| ADMIN role_list
| ROLE role_list
| IN_P (ROLE | GROUP_P) role_list
;
createuserstmt
: CREATE USER roleid with_? optrolelist
;
alterrolestmt
: ALTER (ROLE | USER) rolespec with_? alteroptrolelist
;
in_database_
:
IN_P DATABASE name
;
alterrolesetstmt
: ALTER (ROLE | USER) ALL? rolespec in_database_? setresetclause
;
droprolestmt
: DROP (ROLE | USER | GROUP_P) (IF_P EXISTS)? role_list
;
creategroupstmt
: CREATE GROUP_P roleid with_? optrolelist
;
altergroupstmt
: ALTER GROUP_P rolespec add_drop USER role_list
;
add_drop
: ADD_P
| DROP
;
createschemastmt
: CREATE SCHEMA (IF_P NOT EXISTS)? (optschemaname? AUTHORIZATION rolespec | colid) optschemaeltlist
;
optschemaname
: colid
;
optschemaeltlist
: schema_stmt*
;
schema_stmt
: createstmt
| indexstmt
| createseqstmt
| createtrigstmt
| grantstmt
| viewstmt
;
variablesetstmt
: SET (LOCAL | SESSION)? set_rest
;
set_rest
: TRANSACTION transaction_mode_list
| SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
| set_rest_more
;
generic_set
: var_name (TO | EQUAL) (var_list | DEFAULT)
;
set_rest_more
: generic_set
| var_name FROM CURRENT_P
| TIME ZONE zone_value
| CATALOG sconst
| SCHEMA sconst
| NAMES encoding_?
| ROLE nonreservedword_or_sconst
| SESSION AUTHORIZATION nonreservedword_or_sconst
| XML_P OPTION document_or_content
| TRANSACTION SNAPSHOT sconst
;
var_name
: colid (DOT colid)*
;
var_list
: var_value (COMMA var_value)*
;
var_value
: boolean_or_string_
| numericonly
;
iso_level
: READ (UNCOMMITTED | COMMITTED)
| REPEATABLE READ
| SERIALIZABLE
;
boolean_or_string_
: TRUE_P
| FALSE_P
| ON
| nonreservedword_or_sconst
;
zone_value
: sconst
| identifier
| constinterval sconst interval_?
| constinterval OPEN_PAREN iconst CLOSE_PAREN sconst
| numericonly
| DEFAULT
| LOCAL
;
encoding_
: sconst
| DEFAULT
;
nonreservedword_or_sconst
: nonreservedword
| sconst
;
variableresetstmt
: RESET reset_rest
;
reset_rest
: generic_reset
| TIME ZONE
| TRANSACTION ISOLATION LEVEL
| SESSION AUTHORIZATION
;
generic_reset
: var_name
| ALL
;
setresetclause
: SET set_rest
| variableresetstmt
;
functionsetresetclause
: SET set_rest_more
| variableresetstmt
;
variableshowstmt
: SHOW (var_name | TIME ZONE | TRANSACTION ISOLATION LEVEL | SESSION AUTHORIZATION | ALL)
;
constraintssetstmt
: SET CONSTRAINTS constraints_set_list constraints_set_mode
;
constraints_set_list
: ALL
| qualified_name_list
;
constraints_set_mode
: DEFERRED
| IMMEDIATE
;
checkpointstmt
: CHECKPOINT
;
discardstmt
: DISCARD (ALL | TEMP | TEMPORARY | PLANS | SEQUENCES)
;
altertablestmt
: ALTER TABLE (IF_P EXISTS)? relation_expr (alter_table_cmds | partition_cmd)
| ALTER TABLE ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name nowait_?
| ALTER INDEX (IF_P EXISTS)? qualified_name (alter_table_cmds | index_partition_cmd)
| ALTER INDEX ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name nowait_?
| ALTER SEQUENCE (IF_P EXISTS)? qualified_name alter_table_cmds
| ALTER VIEW (IF_P EXISTS)? qualified_name alter_table_cmds
| ALTER MATERIALIZED VIEW (IF_P EXISTS)? qualified_name alter_table_cmds
| ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name nowait_?
| ALTER FOREIGN TABLE (IF_P EXISTS)? relation_expr alter_table_cmds
;
alter_table_cmds
: alter_table_cmd (COMMA alter_table_cmd)*
;
partition_cmd
: ATTACH PARTITION qualified_name partitionboundspec
| DETACH PARTITION qualified_name
;
index_partition_cmd
: ATTACH PARTITION qualified_name
;
alter_table_cmd
: ADD_P columnDef
| ADD_P IF_P NOT EXISTS columnDef
| ADD_P COLUMN columnDef
| ADD_P COLUMN IF_P NOT EXISTS columnDef
| ALTER column_? colid alter_column_default
| ALTER column_? colid DROP NOT NULL_P
| ALTER column_? colid SET NOT NULL_P
| ALTER column_? colid DROP EXPRESSION
| ALTER column_? colid DROP EXPRESSION IF_P EXISTS
| ALTER column_? colid SET STATISTICS signediconst
| ALTER column_? iconst SET STATISTICS signediconst
| ALTER column_? colid SET reloptions
| ALTER column_? colid RESET reloptions
| ALTER column_? colid SET STORAGE colid
| ALTER column_? colid ADD_P GENERATED generated_when AS IDENTITY_P optparenthesizedseqoptlist?
| ALTER column_? colid alter_identity_column_option_list
| ALTER column_? colid DROP IDENTITY_P
| ALTER column_? colid DROP IDENTITY_P IF_P EXISTS
| DROP column_? IF_P EXISTS colid drop_behavior_?
| DROP column_? colid drop_behavior_?
| ALTER column_? colid set_data_? TYPE_P typename collate_clause_? alter_using?
| ALTER column_? colid alter_generic_options
| ADD_P tableconstraint
| ALTER CONSTRAINT name constraintattributespec
| VALIDATE CONSTRAINT name
| DROP CONSTRAINT IF_P EXISTS name drop_behavior_?
| DROP CONSTRAINT name drop_behavior_?
| SET WITHOUT OIDS
| CLUSTER ON name
| SET WITHOUT CLUSTER
| SET LOGGED
| SET UNLOGGED
| ENABLE_P TRIGGER name
| ENABLE_P ALWAYS TRIGGER name
| ENABLE_P REPLICA TRIGGER name
| ENABLE_P TRIGGER ALL
| ENABLE_P TRIGGER USER
| DISABLE_P TRIGGER name
| DISABLE_P TRIGGER ALL
| DISABLE_P TRIGGER USER
| ENABLE_P RULE name
| ENABLE_P ALWAYS RULE name
| ENABLE_P REPLICA RULE name
| DISABLE_P RULE name
| INHERIT qualified_name
| NO INHERIT qualified_name
| OF any_name
| NOT OF
| OWNER TO rolespec
| SET TABLESPACE name
| SET reloptions
| RESET reloptions
| REPLICA IDENTITY_P replica_identity
| ENABLE_P ROW LEVEL SECURITY
| DISABLE_P ROW LEVEL SECURITY
| FORCE ROW LEVEL SECURITY
| NO FORCE ROW LEVEL SECURITY
| alter_generic_options
;
alter_column_default
: SET DEFAULT a_expr
| DROP DEFAULT
;
drop_behavior_
: CASCADE
| RESTRICT
;
collate_clause_
: COLLATE any_name
;
alter_using
: USING a_expr
;
replica_identity
: NOTHING
| FULL
| DEFAULT
| USING INDEX name
;
reloptions
: OPEN_PAREN reloption_list CLOSE_PAREN
;
reloptions_
: WITH reloptions
;
reloption_list
: reloption_elem (COMMA reloption_elem)*
;
reloption_elem
: colLabel (EQUAL def_arg | DOT colLabel (EQUAL def_arg)?)?
;
alter_identity_column_option_list
: alter_identity_column_option+
;
alter_identity_column_option
: RESTART (with_? numericonly)?
| SET (seqoptelem | GENERATED generated_when)
;
partitionboundspec
: FOR VALUES WITH OPEN_PAREN hash_partbound CLOSE_PAREN
| FOR VALUES IN_P OPEN_PAREN expr_list CLOSE_PAREN
| FOR VALUES FROM OPEN_PAREN expr_list CLOSE_PAREN TO OPEN_PAREN expr_list CLOSE_PAREN
| DEFAULT
;
hash_partbound_elem
: nonreservedword iconst
;
hash_partbound
: hash_partbound_elem (COMMA hash_partbound_elem)*
;
altercompositetypestmt
: ALTER TYPE_P any_name alter_type_cmds
;
alter_type_cmds
: alter_type_cmd (COMMA alter_type_cmd)*
;
alter_type_cmd
: ADD_P ATTRIBUTE tablefuncelement drop_behavior_?
| DROP ATTRIBUTE (IF_P EXISTS)? colid drop_behavior_?
| ALTER ATTRIBUTE colid set_data_? TYPE_P typename collate_clause_? drop_behavior_?
;
closeportalstmt
: CLOSE (cursor_name | ALL)
;
copystmt
: COPY binary_? qualified_name column_list_? copy_from program_? copy_file_name copy_delimiter? with_? copy_options where_clause?
| COPY OPEN_PAREN preparablestmt CLOSE_PAREN TO program_? copy_file_name with_? copy_options
;
copy_from
: FROM
| TO
;
program_
: PROGRAM
;
copy_file_name
: sconst
| STDIN
| STDOUT
;
copy_options
: copy_opt_list
| OPEN_PAREN copy_generic_opt_list CLOSE_PAREN
;
copy_opt_list
: copy_opt_item*
;
copy_opt_item
: BINARY
| FREEZE
| DELIMITER as_? sconst
| NULL_P as_? sconst
| CSV
| HEADER_P
| QUOTE as_? sconst
| ESCAPE as_? sconst
| FORCE QUOTE columnlist
| FORCE QUOTE STAR
| FORCE NOT NULL_P columnlist
| FORCE NULL_P columnlist
| ENCODING sconst
;
binary_
: BINARY
;
copy_delimiter
: using_? DELIMITERS sconst
;
using_
: USING
;
copy_generic_opt_list
: copy_generic_opt_elem (COMMA copy_generic_opt_elem)*
;
copy_generic_opt_elem
: colLabel copy_generic_opt_arg?
;
copy_generic_opt_arg
: boolean_or_string_
| numericonly
| STAR
| OPEN_PAREN copy_generic_opt_arg_list CLOSE_PAREN
;
copy_generic_opt_arg_list
: copy_generic_opt_arg_list_item (COMMA copy_generic_opt_arg_list_item)*
;
copy_generic_opt_arg_list_item
: boolean_or_string_
;
createstmt
: CREATE opttemp? TABLE (IF_P NOT EXISTS)? qualified_name (
OPEN_PAREN opttableelementlist? CLOSE_PAREN optinherit? optpartitionspec? table_access_method_clause? optwith? oncommitoption? opttablespace?
| OF any_name opttypedtableelementlist? optpartitionspec? table_access_method_clause? optwith? oncommitoption? opttablespace?
| PARTITION OF qualified_name opttypedtableelementlist? partitionboundspec optpartitionspec? table_access_method_clause? optwith? oncommitoption?
opttablespace?
)
;
opttemp
: TEMPORARY
| TEMP
| LOCAL (TEMPORARY | TEMP)
| GLOBAL (TEMPORARY | TEMP)
| UNLOGGED
;
opttableelementlist
: tableelementlist
;
opttypedtableelementlist
: OPEN_PAREN typedtableelementlist CLOSE_PAREN
;
tableelementlist
: tableelement (COMMA tableelement)*
;
typedtableelementlist
: typedtableelement (COMMA typedtableelement)*
;
tableelement
: tableconstraint
| tablelikeclause
| columnDef
;
typedtableelement
: columnOptions
| tableconstraint
;
columnDef
: colid typename create_generic_options? colquallist
;
columnOptions
: colid (WITH OPTIONS)? colquallist
;
colquallist
: colconstraint*
;
colconstraint
: CONSTRAINT name colconstraintelem
| colconstraintelem
| constraintattr
| COLLATE any_name
;
colconstraintelem
: NOT NULL_P
| NULL_P
| UNIQUE definition_? optconstablespace?
| PRIMARY KEY definition_? optconstablespace?
| CHECK OPEN_PAREN a_expr CLOSE_PAREN no_inherit_?
| DEFAULT b_expr
| GENERATED generated_when AS (
IDENTITY_P optparenthesizedseqoptlist?
| OPEN_PAREN a_expr CLOSE_PAREN STORED
)
| REFERENCES qualified_name column_list_? key_match? key_actions?
;
generated_when
: ALWAYS
| BY DEFAULT
;
constraintattr
: DEFERRABLE
| NOT DEFERRABLE
| INITIALLY (DEFERRED | IMMEDIATE)
;
tablelikeclause
: LIKE qualified_name tablelikeoptionlist
;
tablelikeoptionlist
: ((INCLUDING | EXCLUDING) tablelikeoption)*
;
tablelikeoption
: COMMENTS
| CONSTRAINTS
| DEFAULTS
| IDENTITY_P
| GENERATED
| INDEXES
| STATISTICS
| STORAGE
| ALL
;
tableconstraint
: CONSTRAINT name constraintelem
| constraintelem
;
constraintelem
: CHECK OPEN_PAREN a_expr CLOSE_PAREN constraintattributespec
| UNIQUE (
OPEN_PAREN columnlist CLOSE_PAREN c_include_? definition_? optconstablespace? constraintattributespec
| existingindex constraintattributespec
)
| PRIMARY KEY (
OPEN_PAREN columnlist CLOSE_PAREN c_include_? definition_? optconstablespace? constraintattributespec
| existingindex constraintattributespec
)
| EXCLUDE access_method_clause? OPEN_PAREN exclusionconstraintlist CLOSE_PAREN c_include_? definition_? optconstablespace? exclusionwhereclause?
constraintattributespec
| FOREIGN KEY OPEN_PAREN columnlist CLOSE_PAREN REFERENCES qualified_name column_list_? key_match? key_actions? constraintattributespec
;
no_inherit_
: NO INHERIT
;
column_list_
: OPEN_PAREN columnlist CLOSE_PAREN
;
columnlist
: columnElem (COMMA columnElem)*
;
columnElem
: colid
;
c_include_
: INCLUDE OPEN_PAREN columnlist CLOSE_PAREN
;
key_match
: MATCH (FULL | PARTIAL | SIMPLE)
;
exclusionconstraintlist
: exclusionconstraintelem (COMMA exclusionconstraintelem)*
;
exclusionconstraintelem
: index_elem WITH (any_operator | OPERATOR OPEN_PAREN any_operator CLOSE_PAREN)
;
exclusionwhereclause
: WHERE OPEN_PAREN a_expr CLOSE_PAREN
;
key_actions
: key_update
| key_delete
| key_update key_delete
| key_delete key_update
;
key_update
: ON UPDATE key_action
;
key_delete
: ON DELETE_P key_action
;
key_action
: NO ACTION
| RESTRICT
| CASCADE
| SET (NULL_P | DEFAULT)
;
optinherit
: INHERITS OPEN_PAREN qualified_name_list CLOSE_PAREN
;
optpartitionspec
: partitionspec
;
partitionspec
: PARTITION BY colid OPEN_PAREN part_params CLOSE_PAREN
;
part_params
: part_elem (COMMA part_elem)*
;
part_elem
: colid collate_? class_?
| func_expr_windowless collate_? class_?
| OPEN_PAREN a_expr CLOSE_PAREN collate_? class_?
;
table_access_method_clause
: USING name
;
optwith
: WITH reloptions
| WITHOUT OIDS
;
oncommitoption
: ON COMMIT (DROP | DELETE_P ROWS | PRESERVE ROWS)
;
opttablespace
: TABLESPACE name
;
optconstablespace
: USING INDEX TABLESPACE name
;
existingindex
: USING INDEX name
;
createstatsstmt
: CREATE STATISTICS (IF_P NOT EXISTS)? any_name name_list_? ON expr_list FROM from_list
;
alterstatsstmt
: ALTER STATISTICS (IF_P EXISTS)? any_name SET STATISTICS signediconst
;
createasstmt
: CREATE opttemp? TABLE (IF_P NOT EXISTS)? create_as_target AS selectstmt with_data_?
;
create_as_target
: qualified_name column_list_? table_access_method_clause? optwith? oncommitoption? opttablespace?
;
with_data_
: WITH (DATA_P | NO DATA_P)
;
creatematviewstmt
: CREATE optnolog? MATERIALIZED VIEW (IF_P NOT EXISTS)? create_mv_target AS selectstmt with_data_?
;
create_mv_target
: qualified_name column_list_? table_access_method_clause? reloptions_? opttablespace?
;
optnolog
: UNLOGGED
;
refreshmatviewstmt
: REFRESH MATERIALIZED VIEW concurrently_? qualified_name with_data_?
;
createseqstmt
: CREATE opttemp? SEQUENCE (IF_P NOT EXISTS)? qualified_name optseqoptlist?
;
alterseqstmt
: ALTER SEQUENCE (IF_P EXISTS)? qualified_name seqoptlist
;
optseqoptlist
: seqoptlist
;
optparenthesizedseqoptlist
: OPEN_PAREN seqoptlist CLOSE_PAREN
;
seqoptlist
: seqoptelem+
;
seqoptelem
: AS simpletypename
| CACHE numericonly
| CYCLE
| INCREMENT by_? numericonly
| MAXVALUE numericonly
| MINVALUE numericonly
| NO (MAXVALUE | MINVALUE | CYCLE)
| OWNED BY any_name
| SEQUENCE NAME_P any_name
| START with_? numericonly
| RESTART with_? numericonly?
;
by_
: BY
;
numericonly
: fconst
| PLUS fconst
| MINUS fconst
| signediconst
;
numericonly_list
: numericonly (COMMA numericonly)*
;
createplangstmt
: CREATE or_replace_? trusted_? procedural_? LANGUAGE name (
HANDLER handler_name inline_handler_? validator_?
)?
;
trusted_
: TRUSTED