forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.y
6535 lines (6094 loc) · 167 KB
/
sql.y
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
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
// Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
// Portions Copyright (c) 1994, Regents of the University of California
%{
package parser
import (
"fmt"
"go/constant"
"go/token"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
)
// MaxUint is the maximum value of an uint.
const MaxUint = ^uint(0)
// MaxInt is the maximum value of an int.
const MaxInt = int(MaxUint >> 1)
func unimplemented(sqllex sqlLexer, feature string) int {
sqllex.(*Scanner).Unimplemented(feature)
return 1
}
func unimplementedWithIssue(sqllex sqlLexer, issue int) int {
sqllex.(*Scanner).UnimplementedWithIssue(issue)
return 1
}
%}
%{
// sqlSymUnion represents a union of types, providing accessor methods
// to retrieve the underlying type stored in the union's empty interface.
// The purpose of the sqlSymUnion struct is to reduce the memory footprint of
// the sqlSymType because only one value (of a variety of types) is ever needed
// to be stored in the union field at a time.
//
// By using an empty interface, we lose the type checking previously provided
// by yacc and the Go compiler when dealing with union values. Instead, runtime
// type assertions must be relied upon in the methods below, and as such, the
// parser should be thoroughly tested whenever new syntax is added.
//
// It is important to note that when assigning values to sqlSymUnion.val, all
// nil values should be typed so that they are stored as nil instances in the
// empty interface, instead of setting the empty interface to nil. This means
// that:
// $$ = []String(nil)
// should be used, instead of:
// $$ = nil
// to assign a nil string slice to the union.
type sqlSymUnion struct {
val interface{}
}
// The following accessor methods come in three forms, depending on the
// type of the value being accessed and whether a nil value is admissible
// for the corresponding grammar rule.
// - Values and pointers are directly type asserted from the empty
// interface, regardless of whether a nil value is admissible or
// not. A panic occurs if the type assertion is incorrect; no panic occurs
// if a nil is not expected but present. (TODO(knz): split this category of
// accessor in two; with one checking for unexpected nils.)
// Examples: bool(), tableWithIdx().
//
// - Interfaces where a nil is admissible are handled differently
// because a nil instance of an interface inserted into the empty interface
// becomes a nil instance of the empty interface and therefore will fail a
// direct type assertion. Instead, a guarded type assertion must be used,
// which returns nil if the type assertion fails.
// Examples: expr(), stmt().
//
// - Interfaces where a nil is not admissible are implemented as a direct
// type assertion, which causes a panic to occur if an unexpected nil
// is encountered.
// Examples: namePart(), tblDef().
//
func (u *sqlSymUnion) numVal() *NumVal {
return u.val.(*NumVal)
}
func (u *sqlSymUnion) strVal() *StrVal {
if stmt, ok := u.val.(*StrVal); ok {
return stmt
}
return nil
}
func (u *sqlSymUnion) bool() bool {
return u.val.(bool)
}
func (u *sqlSymUnion) strPtr() *string {
return u.val.(*string)
}
func (u *sqlSymUnion) strs() []string {
return u.val.([]string)
}
func (u *sqlSymUnion) tableWithIdx() *TableNameWithIndex {
return u.val.(*TableNameWithIndex)
}
func (u *sqlSymUnion) tableWithIdxList() TableNameWithIndexList {
return u.val.(TableNameWithIndexList)
}
func (u *sqlSymUnion) namePart() NamePart {
return u.val.(NamePart)
}
func (u *sqlSymUnion) nameList() NameList {
return u.val.(NameList)
}
func (u *sqlSymUnion) unresolvedName() UnresolvedName {
return u.val.(UnresolvedName)
}
func (u *sqlSymUnion) unresolvedNames() UnresolvedNames {
return u.val.(UnresolvedNames)
}
func (u *sqlSymUnion) functionReference() FunctionReference {
return u.val.(FunctionReference)
}
func (u *sqlSymUnion) resolvableFunctionReference() ResolvableFunctionReference {
return ResolvableFunctionReference{u.val.(FunctionReference)}
}
func (u *sqlSymUnion) normalizableTableName() NormalizableTableName {
return NormalizableTableName{u.val.(TableNameReference)}
}
func (u *sqlSymUnion) newNormalizableTableName() *NormalizableTableName {
return &NormalizableTableName{u.val.(TableNameReference)}
}
func (u *sqlSymUnion) tablePatterns() TablePatterns {
return u.val.(TablePatterns)
}
func (u *sqlSymUnion) tableNameReferences() TableNameReferences {
return u.val.(TableNameReferences)
}
func (u *sqlSymUnion) indexHints() *IndexHints {
return u.val.(*IndexHints)
}
func (u *sqlSymUnion) arraySubscript() *ArraySubscript {
return u.val.(*ArraySubscript)
}
func (u *sqlSymUnion) arraySubscripts() ArraySubscripts {
if as, ok := u.val.(ArraySubscripts); ok {
return as
}
return nil
}
func (u *sqlSymUnion) stmt() Statement {
if stmt, ok := u.val.(Statement); ok {
return stmt
}
return nil
}
func (u *sqlSymUnion) stmts() []Statement {
return u.val.([]Statement)
}
func (u *sqlSymUnion) slct() *Select {
return u.val.(*Select)
}
func (u *sqlSymUnion) selectStmt() SelectStatement {
return u.val.(SelectStatement)
}
func (u *sqlSymUnion) colDef() *ColumnTableDef {
return u.val.(*ColumnTableDef)
}
func (u *sqlSymUnion) constraintDef() ConstraintTableDef {
return u.val.(ConstraintTableDef)
}
func (u *sqlSymUnion) tblDef() TableDef {
return u.val.(TableDef)
}
func (u *sqlSymUnion) tblDefs() TableDefs {
return u.val.(TableDefs)
}
func (u *sqlSymUnion) colQual() NamedColumnQualification {
return u.val.(NamedColumnQualification)
}
func (u *sqlSymUnion) colQualElem() ColumnQualification {
return u.val.(ColumnQualification)
}
func (u *sqlSymUnion) colQuals() []NamedColumnQualification {
return u.val.([]NamedColumnQualification)
}
func (u *sqlSymUnion) colType() ColumnType {
if colType, ok := u.val.(ColumnType); ok {
return colType
}
return nil
}
func (u *sqlSymUnion) tableRefCols() []ColumnID {
if refCols, ok := u.val.([]ColumnID); ok {
return refCols
}
return nil
}
func (u *sqlSymUnion) castTargetType() CastTargetType {
return u.val.(CastTargetType)
}
func (u *sqlSymUnion) colTypes() []ColumnType {
return u.val.([]ColumnType)
}
func (u *sqlSymUnion) expr() Expr {
if expr, ok := u.val.(Expr); ok {
return expr
}
return nil
}
func (u *sqlSymUnion) exprs() Exprs {
return u.val.(Exprs)
}
func (u *sqlSymUnion) selExpr() SelectExpr {
return u.val.(SelectExpr)
}
func (u *sqlSymUnion) selExprs() SelectExprs {
return u.val.(SelectExprs)
}
func (u *sqlSymUnion) retClause() ReturningClause {
return u.val.(ReturningClause)
}
func (u *sqlSymUnion) aliasClause() AliasClause {
return u.val.(AliasClause)
}
func (u *sqlSymUnion) asOfClause() AsOfClause {
return u.val.(AsOfClause)
}
func (u *sqlSymUnion) tblExpr() TableExpr {
return u.val.(TableExpr)
}
func (u *sqlSymUnion) tblExprs() TableExprs {
return u.val.(TableExprs)
}
func (u *sqlSymUnion) from() *From {
return u.val.(*From)
}
func (u *sqlSymUnion) joinCond() JoinCond {
return u.val.(JoinCond)
}
func (u *sqlSymUnion) when() *When {
return u.val.(*When)
}
func (u *sqlSymUnion) whens() []*When {
return u.val.([]*When)
}
func (u *sqlSymUnion) updateExpr() *UpdateExpr {
return u.val.(*UpdateExpr)
}
func (u *sqlSymUnion) updateExprs() UpdateExprs {
return u.val.(UpdateExprs)
}
func (u *sqlSymUnion) limit() *Limit {
return u.val.(*Limit)
}
func (u *sqlSymUnion) targetList() TargetList {
return u.val.(TargetList)
}
func (u *sqlSymUnion) targetListPtr() *TargetList {
return u.val.(*TargetList)
}
func (u *sqlSymUnion) privilegeType() privilege.Kind {
return u.val.(privilege.Kind)
}
func (u *sqlSymUnion) privilegeList() privilege.List {
return u.val.(privilege.List)
}
func (u *sqlSymUnion) onConflict() *OnConflict {
return u.val.(*OnConflict)
}
func (u *sqlSymUnion) orderBy() OrderBy {
return u.val.(OrderBy)
}
func (u *sqlSymUnion) order() *Order {
return u.val.(*Order)
}
func (u *sqlSymUnion) orders() []*Order {
return u.val.([]*Order)
}
func (u *sqlSymUnion) groupBy() GroupBy {
return u.val.(GroupBy)
}
func (u *sqlSymUnion) dir() Direction {
return u.val.(Direction)
}
func (u *sqlSymUnion) alterTableCmd() AlterTableCmd {
return u.val.(AlterTableCmd)
}
func (u *sqlSymUnion) alterTableCmds() AlterTableCmds {
return u.val.(AlterTableCmds)
}
func (u *sqlSymUnion) isoLevel() IsolationLevel {
return u.val.(IsolationLevel)
}
func (u *sqlSymUnion) userPriority() UserPriority {
return u.val.(UserPriority)
}
func (u *sqlSymUnion) readWriteMode() ReadWriteMode {
return u.val.(ReadWriteMode)
}
func (u *sqlSymUnion) idxElem() IndexElem {
return u.val.(IndexElem)
}
func (u *sqlSymUnion) idxElems() IndexElemList {
return u.val.(IndexElemList)
}
func (u *sqlSymUnion) dropBehavior() DropBehavior {
return u.val.(DropBehavior)
}
func (u *sqlSymUnion) validationBehavior() ValidationBehavior {
return u.val.(ValidationBehavior)
}
func (u *sqlSymUnion) interleave() *InterleaveDef {
return u.val.(*InterleaveDef)
}
func (u *sqlSymUnion) windowDef() *WindowDef {
return u.val.(*WindowDef)
}
func (u *sqlSymUnion) window() Window {
return u.val.(Window)
}
func (u *sqlSymUnion) op() operator {
return u.val.(operator)
}
func (u *sqlSymUnion) cmpOp() ComparisonOperator {
return u.val.(ComparisonOperator)
}
func (u *sqlSymUnion) durationField() durationField {
return u.val.(durationField)
}
func (u *sqlSymUnion) kvOption() KVOption {
return u.val.(KVOption)
}
func (u *sqlSymUnion) kvOptions() []KVOption {
if colType, ok := u.val.([]KVOption); ok {
return colType
}
return nil
}
func (u *sqlSymUnion) transactionModes() TransactionModes {
return u.val.(TransactionModes)
}
%}
// NB: the %token definitions must come before the %type definitions in this
// file to work around a bug in goyacc. See #16369 for more details.
// Non-keyword token types.
%token <str> IDENT SCONST BCONST
%token <*NumVal> ICONST FCONST
%token <str> PLACEHOLDER
%token <str> TYPECAST TYPEANNOTATE DOT_DOT
%token <str> LESS_EQUALS GREATER_EQUALS NOT_EQUALS
%token <str> NOT_REGMATCH REGIMATCH NOT_REGIMATCH
%token <str> ERROR
// If you want to make any keyword changes, add the new keyword here as well as
// to the appropriate one of the reserved-or-not-so-reserved keyword lists,
// below; search this file for "Keyword category lists".
// Ordinary key words in alphabetical order.
%token <str> ACTION ADD
%token <str> ALL ALTER ANALYSE ANALYZE AND ANY ANNOTATE_TYPE ARRAY AS ASC
%token <str> ASYMMETRIC AT
%token <str> BACKUP BEGIN BETWEEN BIGINT BIGSERIAL BIT
%token <str> BLOB BOOL BOOLEAN BOTH BY BYTEA BYTES
%token <str> CANCEL CASCADE CASE CAST CHAR
%token <str> CHARACTER CHARACTERISTICS CHECK
%token <str> CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMIT
%token <str> COMMITTED CONCAT CONFLICT CONSTRAINT CONSTRAINTS
%token <str> COPY COVERING CREATE
%token <str> CROSS CSV CUBE CURRENT CURRENT_CATALOG CURRENT_DATE CURRENT_SCHEMA
%token <str> CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP
%token <str> CURRENT_USER CYCLE
%token <str> DATA DATABASE DATABASES DATE DAY DEC DECIMAL DEFAULT
%token <str> DEALLOCATE DEFERRABLE DELETE DESC
%token <str> DISCARD DISTINCT DO DOUBLE DROP
%token <str> ELSE ENCODING END ESCAPE EXCEPT
%token <str> EXISTS EXECUTE EXPERIMENTAL_FINGERPRINTS EXPLAIN EXTRACT EXTRACT_DURATION
%token <str> FALSE FAMILY FETCH FILTER FIRST FLOAT FLOAT4 FLOAT8 FLOORDIV FOLLOWING FOR
%token <str> FORCE_INDEX FOREIGN FROM FULL
%token <str> GRANT GRANTS GREATEST GROUP GROUPING
%token <str> HAVING HELP HIGH HOUR
%token <str> IMPORT INCREMENTAL IF IFNULL ILIKE IN INTERLEAVE
%token <str> INDEX INDEXES INITIALLY
%token <str> INNER INSERT INT INT2VECTOR INT2 INT4 INT8 INT64 INTEGER
%token <str> INTERSECT INTERVAL INTO IS ISOLATION
%token <str> JOB JOBS JOIN
%token <str> KEY KEYS KV
%token <str> LATERAL LC_CTYPE LC_COLLATE
%token <str> LEADING LEAST LEFT LEVEL LIKE LIMIT LOCAL
%token <str> LOCALTIME LOCALTIMESTAMP LOW LSHIFT
%token <str> MATCH MINUTE MONTH
%token <str> NAN NAME NAMES NATURAL NEXT NO NO_INDEX_JOIN NORMAL
%token <str> NOT NOTHING NULL NULLIF
%token <str> NULLS NUMERIC
%token <str> OF OFF OFFSET OID ON ONLY OPTIONS OR
%token <str> ORDER ORDINALITY OUT OUTER OVER OVERLAPS OVERLAY
%token <str> PARENT PARTIAL PARTITION PASSWORD PAUSE PLACING PLANS POSITION
%token <str> PRECEDING PRECISION PREPARE PRIMARY PRIORITY
%token <str> QUERIES QUERY
%token <str> RANGE READ REAL RECURSIVE REF REFERENCES
%token <str> REGCLASS REGPROC REGPROCEDURE REGNAMESPACE REGTYPE
%token <str> RENAME REPEATABLE
%token <str> RELEASE RESET RESTORE RESTRICT RESUME RETURNING REVOKE RIGHT
%token <str> ROLLBACK ROLLUP ROW ROWS RSHIFT
%token <str> SAVEPOINT SCATTER SEARCH SECOND SELECT SEQUENCES
%token <str> SERIAL SERIALIZABLE SESSION SESSIONS SESSION_USER SET SETTING SETTINGS
%token <str> SHOW SIMILAR SIMPLE SMALLINT SMALLSERIAL SNAPSHOT SOME SPLIT SQL
%token <str> START STATUS STDIN STRICT STRING STORE STORING SUBSTRING
%token <str> SYMMETRIC SYSTEM
%token <str> TABLE TABLES TEMP TEMPLATE TEMPORARY TESTING_RANGES TESTING_RELOCATE TEXT THEN
%token <str> TIME TIMESTAMP TIMESTAMPTZ TO TRAILING TRACE TRANSACTION TREAT TRIM TRUE
%token <str> TRUNCATE TYPE
%token <str> UNBOUNDED UNCOMMITTED UNION UNIQUE UNKNOWN
%token <str> UPDATE UPSERT USE USER USERS USING UUID
%token <str> VALID VALIDATE VALUE VALUES VARCHAR VARIADIC VIEW VARYING
%token <str> WHEN WHERE WINDOW WITH WITHIN WITHOUT WRITE
%token <str> YEAR
%token <str> ZONE
// The grammar thinks these are keywords, but they are not in any category
// and so can never be entered directly. The filter in scan.go creates these
// tokens when required (based on looking one token ahead).
//
// NOT_LA exists so that productions such as NOT LIKE can be given the same
// precedence as LIKE; otherwise they'd effectively have the same precedence as
// NOT, at least with respect to their left-hand subexpression. WITH_LA is
// needed to make the grammar LALR(1).
%token NOT_LA WITH_LA AS_LA
%union {
id int
pos int
empty struct{}
str string
union sqlSymUnion
}
%type <[]Statement> stmt_block
%type <[]Statement> stmt_list
%type <Statement> stmt
%type <Statement> alter_stmt
%type <Statement> alter_table_stmt
%type <Statement> alter_index_stmt
%type <Statement> alter_view_stmt
%type <Statement> alter_database_stmt
// ALTER TABLE
%type <Statement> alter_onetable_stmt
%type <Statement> alter_split_stmt
%type <Statement> alter_rename_table_stmt
%type <Statement> alter_scatter_stmt
%type <Statement> alter_testing_relocate_stmt
// ALTER DATABASE
%type <Statement> alter_rename_database_stmt
// ALTER INDEX
%type <Statement> alter_scatter_index_stmt
%type <Statement> alter_split_index_stmt
%type <Statement> alter_rename_index_stmt
%type <Statement> alter_testing_relocate_index_stmt
// ALTER VIEW
%type <Statement> alter_rename_view_stmt
%type <Statement> backup_stmt
%type <Statement> begin_stmt
%type <Statement> cancel_stmt
%type <Statement> cancel_job_stmt
%type <Statement> cancel_query_stmt
%type <Statement> commit_stmt
%type <Statement> copy_from_stmt
%type <Statement> create_stmt
%type <Statement> create_database_stmt
%type <Statement> create_index_stmt
%type <Statement> create_table_stmt
%type <Statement> create_table_as_stmt
%type <Statement> create_user_stmt
%type <Statement> create_view_stmt
%type <Statement> delete_stmt
%type <Statement> discard_stmt
%type <Statement> drop_stmt
%type <Statement> drop_database_stmt
%type <Statement> drop_index_stmt
%type <Statement> drop_table_stmt
%type <Statement> drop_user_stmt
%type <Statement> drop_view_stmt
%type <Statement> explain_stmt
%type <Statement> prepare_stmt
%type <Statement> preparable_stmt
%type <Statement> explainable_stmt
%type <Statement> execute_stmt
%type <Statement> deallocate_stmt
%type <Statement> grant_stmt
%type <Statement> insert_stmt
%type <Statement> import_stmt
%type <Statement> pause_stmt
%type <Statement> release_stmt
%type <Statement> reset_stmt reset_session_stmt reset_csetting_stmt
%type <Statement> resume_stmt
%type <Statement> restore_stmt
%type <Statement> revoke_stmt
%type <*Select> select_stmt
%type <Statement> rollback_stmt
%type <Statement> savepoint_stmt
%type <Statement> set_stmt
%type <Statement> set_session_stmt
%type <Statement> set_csetting_stmt
%type <Statement> set_transaction_stmt
%type <Statement> set_exprs_internal
%type <Statement> generic_set
%type <Statement> set_rest_more
%type <Statement> set_names
%type <Statement> show_stmt
%type <Statement> show_backup_stmt
%type <Statement> show_columns_stmt
%type <Statement> show_constraints_stmt
%type <Statement> show_create_table_stmt
%type <Statement> show_create_view_stmt
%type <Statement> show_csettings_stmt
%type <Statement> show_databases_stmt
%type <Statement> show_grants_stmt
%type <Statement> show_indexes_stmt
%type <Statement> show_jobs_stmt
%type <Statement> show_queries_stmt
%type <Statement> show_session_stmt
%type <Statement> show_sessions_stmt
%type <Statement> show_tables_stmt
%type <Statement> show_testing_stmt
%type <Statement> show_trace_stmt
%type <Statement> show_transaction_stmt
%type <Statement> show_users_stmt
%type <str> session_var
%type <Statement> transaction_stmt
%type <Statement> truncate_stmt
%type <Statement> update_stmt
%type <Statement> upsert_stmt
%type <Statement> use_stmt
%type <[]string> opt_incremental
%type <KVOption> kv_option
%type <[]KVOption> kv_option_list opt_with_options
%type <str> import_data_format
%type <*Select> select_no_parens
%type <SelectStatement> select_clause select_with_parens simple_select values_clause table_clause simple_select_clause
%type <SelectStatement> set_operation
%type <empty> alter_using
%type <Expr> alter_column_default
%type <Direction> opt_asc_desc
%type <AlterTableCmd> alter_table_cmd
%type <AlterTableCmds> alter_table_cmds
%type <empty> opt_collate_clause
%type <DropBehavior> opt_drop_behavior
%type <DropBehavior> opt_interleave_drop_behavior
%type <ValidationBehavior> opt_validate_behavior
%type <str> opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
%type <*string> opt_password
%type <IsolationLevel> transaction_iso_level
%type <UserPriority> transaction_user_priority
%type <ReadWriteMode> transaction_read_mode
%type <str> name opt_name opt_name_parens opt_to_savepoint
%type <str> savepoint_name
%type <operator> subquery_op
%type <FunctionReference> func_name
%type <empty> opt_collate
%type <UnresolvedName> qualified_name
%type <UnresolvedName> table_pattern
%type <TableExpr> insert_target
%type <*TableNameWithIndex> table_name_with_index
%type <TableNameWithIndexList> table_name_with_index_list
%type <operator> math_op
%type <IsolationLevel> iso_level
%type <UserPriority> user_priority
%type <TableDefs> opt_table_elem_list table_elem_list
%type <*InterleaveDef> opt_interleave
%type <empty> opt_all_clause
%type <bool> distinct_clause
%type <NameList> opt_column_list
%type <OrderBy> sort_clause opt_sort_clause
%type <[]*Order> sortby_list
%type <IndexElemList> index_params
%type <NameList> name_list opt_name_list
%type <Exprs> opt_array_bounds
%type <*From> from_clause update_from_clause
%type <TableExprs> from_list
%type <UnresolvedNames> qualified_name_list
%type <TablePatterns> table_pattern_list
%type <UnresolvedName> any_name
%type <TableNameReferences> table_name_list
%type <Exprs> expr_list
%type <UnresolvedName> attrs
%type <SelectExprs> target_list
%type <UpdateExprs> set_clause_list
%type <*UpdateExpr> set_clause multiple_set_clause
%type <ArraySubscripts> array_subscripts
%type <UnresolvedName> qname_indirection
%type <NamePart> name_indirection_elem
%type <Exprs> ctext_expr_list ctext_row
%type <GroupBy> group_clause
%type <*Limit> select_limit
%type <TableNameReferences> relation_expr_list
%type <ReturningClause> returning_clause
%type <bool> all_or_distinct
%type <empty> join_outer
%type <JoinCond> join_qual
%type <str> join_type
%type <Exprs> extract_list
%type <Exprs> overlay_list
%type <Exprs> position_list
%type <Exprs> substr_list
%type <Exprs> trim_list
%type <Exprs> execute_param_clause
%type <durationField> opt_interval interval_second
%type <Expr> overlay_placing
%type <bool> opt_unique opt_column
%type <empty> opt_set_data
%type <*Limit> limit_clause offset_clause opt_limit_clause
%type <Expr> select_limit_value
%type <Expr> opt_select_fetch_first_value
%type <empty> row_or_rows
%type <empty> first_or_next
%type <Statement> insert_rest
%type <NameList> opt_conf_expr
%type <*OnConflict> on_conflict
%type <Statement> begin_transaction
%type <TransactionModes> transaction_mode_list transaction_mode
%type <NameList> opt_storing
%type <*ColumnTableDef> column_def
%type <TableDef> table_elem
%type <Expr> where_clause
%type <NamePart> glob_indirection
%type <NamePart> name_indirection
%type <*ArraySubscript> array_subscript
%type <Expr> opt_slice_bound
%type <*IndexHints> opt_index_hints
%type <*IndexHints> index_hints_param
%type <*IndexHints> index_hints_param_list
%type <Expr> a_expr b_expr c_expr a_expr_const d_expr
%type <Expr> substr_from substr_for
%type <Expr> in_expr
%type <Expr> having_clause
%type <Expr> array_expr
%type <Expr> interval
%type <[]ColumnType> type_list prep_type_clause
%type <Exprs> array_expr_list
%type <Expr> row explicit_row implicit_row
%type <Expr> case_expr case_arg case_default
%type <*When> when_clause
%type <[]*When> when_clause_list
%type <ComparisonOperator> sub_type
%type <Expr> ctext_expr
%type <Expr> numeric_only
%type <AliasClause> alias_clause opt_alias_clause
%type <bool> opt_ordinality
%type <*Order> sortby
%type <IndexElem> index_elem
%type <TableExpr> table_ref
%type <TableExpr> joined_table
%type <UnresolvedName> relation_expr
%type <TableExpr> relation_expr_opt_alias
%type <SelectExpr> target_elem
%type <*UpdateExpr> single_set_clause
%type <AsOfClause> opt_as_of_clause
%type <str> explain_option_name
%type <[]string> explain_option_list
%type <ColumnType> typename simple_typename const_typename
%type <ColumnType> numeric opt_numeric_modifiers
%type <*NumVal> opt_float
%type <ColumnType> character const_character
%type <ColumnType> character_with_length character_without_length
%type <ColumnType> const_datetime const_interval
%type <ColumnType> bit const_bit bit_with_length bit_without_length
%type <ColumnType> character_base
%type <CastTargetType> postgres_oid
%type <CastTargetType> cast_target
%type <str> extract_arg
%type <empty> opt_varying
%type <*NumVal> signed_iconst
%type <Expr> var_value
%type <Exprs> var_list
%type <UnresolvedName> var_name
%type <str> unrestricted_name type_function_name
%type <str> non_reserved_word
%type <str> non_reserved_word_or_sconst
%type <Expr> zone_value
%type <Expr> string_or_placeholder
%type <Expr> string_or_placeholder_list
%type <str> unreserved_keyword type_func_name_keyword
%type <str> col_name_keyword reserved_keyword
%type <ConstraintTableDef> table_constraint constraint_elem
%type <TableDef> index_def
%type <TableDef> family_def
%type <[]NamedColumnQualification> col_qual_list
%type <NamedColumnQualification> col_qualification
%type <ColumnQualification> col_qualification_elem
%type <empty> key_actions key_delete key_match key_update key_action
%type <Expr> func_application func_expr_common_subexpr
%type <Expr> func_expr func_expr_windowless
%type <empty> common_table_expr
%type <empty> with_clause opt_with opt_with_clause
%type <empty> cte_list
%type <empty> within_group_clause
%type <Expr> filter_clause
%type <Exprs> opt_partition_clause
%type <Window> window_clause window_definition_list
%type <*WindowDef> window_definition over_clause window_specification
%type <str> opt_existing_window_name
%type <empty> opt_frame_clause frame_extent frame_bound
%type <[]ColumnID> opt_tableref_col_list tableref_col_list
%type <TargetList> targets
%type <*TargetList> on_privilege_target_clause
%type <NameList> grantee_list for_grantee_clause
%type <privilege.List> privileges privilege_list
%type <privilege.Kind> privilege
// Precedence: lowest to highest
%nonassoc VALUES // see value_clause
%nonassoc SET // see relation_expr_opt_alias
%left UNION EXCEPT
%left INTERSECT
%left OR
%left AND
%right NOT
%nonassoc IS // IS sets precedence for IS NULL, etc
%nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
%nonassoc '~' BETWEEN IN LIKE ILIKE SIMILAR NOT_REGMATCH REGIMATCH NOT_REGIMATCH NOT_LA
%nonassoc ESCAPE // ESCAPE must be just above LIKE/ILIKE/SIMILAR
%nonassoc OVERLAPS
%left POSTFIXOP // dummy for postfix OP rules
// To support target_elem without AS, we must give IDENT an explicit priority
// between POSTFIXOP and OP. We can safely assign the same priority to various
// unreserved keywords as needed to resolve ambiguities (this can't have any
// bad effects since obviously the keywords will still behave the same as if
// they weren't keywords). We need to do this for PARTITION, RANGE, ROWS to
// support opt_existing_window_name; and for RANGE, ROWS so that they can
// follow a_expr without creating postfix-operator problems; and for NULL so
// that it can follow b_expr in col_qual_list without creating postfix-operator
// problems.
//
// To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
// an explicit priority lower than '(', so that a rule with CUBE '(' will shift
// rather than reducing a conflicting rule that takes CUBE as a function name.
// Using the same precedence as IDENT seems right for the reasons given above.
//
// The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING are
// even messier: since UNBOUNDED is an unreserved keyword (per spec!), there is
// no principled way to distinguish these from the productions a_expr
// PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly lower
// precedence than PRECEDING and FOLLOWING. At present this doesn't appear to
// cause UNBOUNDED to be treated differently from other unreserved keywords
// anywhere else in the grammar, but it's definitely risky. We can blame any
// funny behavior of UNBOUNDED on the SQL standard, though.
%nonassoc UNBOUNDED // ideally should have same precedence as IDENT
%nonassoc IDENT NULL PARTITION RANGE ROWS PRECEDING FOLLOWING CUBE ROLLUP
%left CONCAT // multi-character ops
%left '|'
%left '#'
%left '&'
%left LSHIFT RSHIFT
%left '+' '-'
%left '*' '/' FLOORDIV '%'
%left '^'
// Unary Operators
%left AT // sets precedence for AT TIME ZONE
%left COLLATE
%right UMINUS
%left '[' ']'
%left '(' ')'
%left TYPEANNOTATE
%left TYPECAST
%left '.'
// These might seem to be low-precedence, but actually they are not part
// of the arithmetic hierarchy at all in their use as JOIN operators.
// We make them high-precedence to support their use as function names.
// They wouldn't be given a precedence at all, were it not that we need
// left-associativity among the JOIN rules themselves.
%left JOIN CROSS LEFT FULL RIGHT INNER NATURAL
%right HELPTOKEN
%%
stmt_block:
stmt_list
{
sqllex.(*Scanner).stmts = $1.stmts()
}
stmt_list:
stmt_list ';' stmt
{
if $3.stmt() != nil {
$$.val = append($1.stmts(), $3.stmt())
}
}
| stmt
{
if $1.stmt() != nil {
$$.val = []Statement{$1.stmt()}
} else {
$$.val = []Statement(nil)
}
}
stmt:
HELPTOKEN { return helpWith(sqllex, "") }
| alter_stmt // help texts in sub-rule
| backup_stmt // EXTEND WITH HELP: BACKUP
| cancel_stmt // help texts in sub-rule
| copy_from_stmt
| create_stmt // help texts in sub-rule
| deallocate_stmt // EXTEND WITH HELP: DEALLOCATE
| delete_stmt // EXTEND WITH HELP: DELETE
| discard_stmt // EXTEND WITH HELP: DISCARD
| drop_stmt // help texts in sub-rule
| execute_stmt // EXTEND WITH HELP: EXECUTE
| explain_stmt // EXTEND WITH HELP: EXPLAIN
| grant_stmt // EXTEND WITH HELP: GRANT
| insert_stmt // EXTEND WITH HELP: INSERT
| import_stmt // EXTEND WITH HELP: IMPORT
| pause_stmt // EXTEND WITH HELP: PAUSE JOB
| prepare_stmt // EXTEND WITH HELP: PREPARE
| restore_stmt // EXTEND WITH HELP: RESTORE
| resume_stmt // EXTEND WITH HELP: RESUME JOB
| revoke_stmt // EXTEND WITH HELP: REVOKE
| savepoint_stmt // EXTEND WITH HELP: SAVEPOINT
| select_stmt // help texts in sub-rule
{
$$.val = $1.slct()
}
| release_stmt // EXTEND WITH HELP: RELEASE
| reset_stmt // help texts in sub-rule
| set_stmt // help texts in sub-rule
| show_stmt // help texts in sub-rule
| transaction_stmt // help texts in sub-rule
| truncate_stmt // EXTEND WITH HELP: TRUNCATE
| update_stmt // EXTEND WITH HELP: UPDATE
| upsert_stmt // EXTEND WITH HELP: UPSERT
| /* EMPTY */
{
$$.val = Statement(nil)
}
// %Help: ALTER
// %Category: Group
// %Text: ALTER TABLE, ALTER INDEX, ALTER VIEW, ALTER DATABASE
alter_stmt:
alter_table_stmt // EXTEND WITH HELP: ALTER TABLE
| alter_index_stmt // EXTEND WITH HELP: ALTER INDEX
| alter_view_stmt // EXTEND WITH HELP: ALTER VIEW
| alter_database_stmt // EXTEND WITH HELP: ALTER DATABASE
| ALTER error // SHOW HELP: ALTER
// %Help: ALTER TABLE - change the definition of a table
// %Category: DDL
// %Text:
// ALTER TABLE [IF EXISTS] <tablename> <command> [, ...]
//
// Commands:
// ALTER TABLE ... ADD [COLUMN] [IF NOT EXISTS] <colname> <type> [<qualifiers...>]
// ALTER TABLE ... ADD <constraint>
// ALTER TABLE ... DROP [COLUMN] [IF EXISTS] <colname> [RESTRICT | CASCADE]
// ALTER TABLE ... DROP CONSTRAINT [IF EXISTS] <constraintname> [RESTRICT | CASCADE]
// ALTER TABLE ... ALTER [COLUMN] <colname> {SET DEFAULT <expr> | DROP DEFAULT}
// ALTER TABLE ... ALTER [COLUMN] <colname> DROP NOT NULL
// ALTER TABLE ... RENAME TO <newname>
// ALTER TABLE ... RENAME [COLUMN] <colname> TO <newname>
// ALTER TABLE ... VALIDATE CONSTRAINT <constraintname>
// ALTER TABLE ... SPLIT AT <selectclause>
// ALTER TABLE ... SCATTER [ FROM ( <exprs...> ) TO ( <exprs...> ) ]
//
// Column qualifiers:
// [CONSTRAINT <constraintname>] {NULL | NOT NULL | UNIQUE | PRIMARY KEY | CHECK (<expr>) | DEFAULT <expr>}
// FAMILY <familyname>, CREATE [IF NOT EXISTS] FAMILY [<familyname>]
// REFERENCES <tablename> [( <colnames...> )]
// COLLATE <collationname>
//
// %SeeAlso: WEBDOCS/alter-table.html
alter_table_stmt:
alter_onetable_stmt
| alter_split_stmt
| alter_testing_relocate_stmt
| alter_scatter_stmt
| alter_rename_table_stmt
// ALTER TABLE has its error help token here because the ALTER TABLE
// prefix is spread over multiple non-terminals.
| ALTER TABLE error // SHOW HELP: ALTER TABLE
// %Help: ALTER VIEW - change the definition of a view
// %Category: DDL
// %Text:
// ALTER VIEW [IF EXISTS] <name> RENAME TO <newname>
// %SeeAlso: WEBDOCS/alter-view.html
alter_view_stmt:
alter_rename_view_stmt
// ALTER VIEW has its error help token here because the ALTER VIEW
// prefix is spread over multiple non-terminals.
| ALTER VIEW error // SHOW HELP: ALTER VIEW
// %Help: ALTER DATABASE - change the definition of a database
// %Category: DDL
// %Text:
// ALTER DATABASE <name> RENAME TO <newname>
// %SeeAlso: WEBDOCS/alter-database.html
alter_database_stmt:
alter_rename_database_stmt
// ALTER DATABASE has its error help token here because the ALTER DATABASE
// prefix is spread over multiple non-terminals.
| ALTER DATABASE error // SHOW HELP: ALTER DATABASE
// %Help: ALTER INDEX - change the definition of an index
// %Category: DDL
// %Text:
// ALTER INDEX [IF EXISTS] <idxname> <command>
//
// Commands:
// ALTER INDEX ... RENAME TO <newname>
// ALTER INDEX ... SPLIT AT <selectclause>
// ALTER INDEX ... SCATTER [ FROM ( <exprs...> ) TO ( <exprs...> ) ]
//
// %SeeAlso: WEBDOCS/alter-index.html
alter_index_stmt:
alter_split_index_stmt
| alter_testing_relocate_index_stmt
| alter_scatter_index_stmt
| alter_rename_index_stmt