// Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group // Portions Copyright (c) 1994, Regents of the University of California // Portions of this file are additionally subject to the following // license and copyright. // // 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. // Going to add a new statement? // Consider taking a look at our codelab guide to learn what is needed to add a statement. // https://github.com/cockroachdb/cockroach/blob/master/docs/codelabs/01-sql-statement.md %{ package parser import ( "fmt" "strings" "go/constant" "github.com/forhsd/postgresql-parser/pkg/sql/lex" "github.com/forhsd/postgresql-parser/pkg/sql/privilege" "github.com/forhsd/postgresql-parser/pkg/sql/roleoption" "github.com/forhsd/postgresql-parser/pkg/sql/sem/tree" "github.com/forhsd/postgresql-parser/pkg/sql/types" ) // 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.(*lexer).Unimplemented(feature) return 1 } func purposelyUnimplemented(sqllex sqlLexer, feature string, reason string) int { sqllex.(*lexer).PurposelyUnimplemented(feature, reason) return 1 } func setErr(sqllex sqlLexer, err error) int { sqllex.(*lexer).setErr(err) return 1 } func unimplementedWithIssue(sqllex sqlLexer, issue int) int { sqllex.(*lexer).UnimplementedWithIssue(issue) return 1 } func unimplementedWithIssueDetail(sqllex sqlLexer, issue int, detail string) int { sqllex.(*lexer).UnimplementedWithIssueDetail(issue, detail) 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(), tableIndexName(). // // - 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: tblDef(). // func (u *sqlSymUnion) numVal() *tree.NumVal { return u.val.(*tree.NumVal) } func (u *sqlSymUnion) strVal() *tree.StrVal { if stmt, ok := u.val.(*tree.StrVal); ok { return stmt } return nil } func (u *sqlSymUnion) placeholder() *tree.Placeholder { return u.val.(*tree.Placeholder) } func (u *sqlSymUnion) auditMode() tree.AuditMode { return u.val.(tree.AuditMode) } 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) newTableIndexName() *tree.TableIndexName { tn := u.val.(tree.TableIndexName) return &tn } func (u *sqlSymUnion) tableIndexName() tree.TableIndexName { return u.val.(tree.TableIndexName) } func (u *sqlSymUnion) newTableIndexNames() tree.TableIndexNames { return u.val.(tree.TableIndexNames) } func (u *sqlSymUnion) shardedIndexDef() *tree.ShardedIndexDef { return u.val.(*tree.ShardedIndexDef) } func (u *sqlSymUnion) nameList() tree.NameList { return u.val.(tree.NameList) } func (u *sqlSymUnion) unresolvedName() *tree.UnresolvedName { return u.val.(*tree.UnresolvedName) } func (u *sqlSymUnion) unresolvedObjectName() *tree.UnresolvedObjectName { return u.val.(*tree.UnresolvedObjectName) } func (u *sqlSymUnion) functionReference() tree.FunctionReference { return u.val.(tree.FunctionReference) } func (u *sqlSymUnion) tablePatterns() tree.TablePatterns { return u.val.(tree.TablePatterns) } func (u *sqlSymUnion) tableNames() tree.TableNames { return u.val.(tree.TableNames) } func (u *sqlSymUnion) indexFlags() *tree.IndexFlags { return u.val.(*tree.IndexFlags) } func (u *sqlSymUnion) arraySubscript() *tree.ArraySubscript { return u.val.(*tree.ArraySubscript) } func (u *sqlSymUnion) arraySubscripts() tree.ArraySubscripts { if as, ok := u.val.(tree.ArraySubscripts); ok { return as } return nil } func (u *sqlSymUnion) stmt() tree.Statement { if stmt, ok := u.val.(tree.Statement); ok { return stmt } return nil } func (u *sqlSymUnion) cte() *tree.CTE { if cte, ok := u.val.(*tree.CTE); ok { return cte } return nil } func (u *sqlSymUnion) ctes() []*tree.CTE { return u.val.([]*tree.CTE) } func (u *sqlSymUnion) with() *tree.With { if with, ok := u.val.(*tree.With); ok { return with } return nil } func (u *sqlSymUnion) slct() *tree.Select { return u.val.(*tree.Select) } func (u *sqlSymUnion) selectStmt() tree.SelectStatement { return u.val.(tree.SelectStatement) } func (u *sqlSymUnion) colDef() *tree.ColumnTableDef { return u.val.(*tree.ColumnTableDef) } func (u *sqlSymUnion) constraintDef() tree.ConstraintTableDef { return u.val.(tree.ConstraintTableDef) } func (u *sqlSymUnion) tblDef() tree.TableDef { return u.val.(tree.TableDef) } func (u *sqlSymUnion) tblDefs() tree.TableDefs { return u.val.(tree.TableDefs) } func (u *sqlSymUnion) colQual() tree.NamedColumnQualification { return u.val.(tree.NamedColumnQualification) } func (u *sqlSymUnion) colQualElem() tree.ColumnQualification { return u.val.(tree.ColumnQualification) } func (u *sqlSymUnion) colQuals() []tree.NamedColumnQualification { return u.val.([]tree.NamedColumnQualification) } func (u *sqlSymUnion) storageParam() tree.StorageParam { return u.val.(tree.StorageParam) } func (u *sqlSymUnion) storageParams() []tree.StorageParam { if params, ok := u.val.([]tree.StorageParam); ok { return params } return nil } func (u *sqlSymUnion) persistenceType() bool { return u.val.(bool) } func (u *sqlSymUnion) colType() *types.T { if colType, ok := u.val.(*types.T); ok && colType != nil { return colType } return nil } func (u *sqlSymUnion) tableRefCols() []tree.ColumnID { if refCols, ok := u.val.([]tree.ColumnID); ok { return refCols } return nil } func (u *sqlSymUnion) colTypes() []*types.T { return u.val.([]*types.T) } func (u *sqlSymUnion) int32() int32 { return u.val.(int32) } func (u *sqlSymUnion) int64() int64 { return u.val.(int64) } func (u *sqlSymUnion) seqOpt() tree.SequenceOption { return u.val.(tree.SequenceOption) } func (u *sqlSymUnion) seqOpts() []tree.SequenceOption { return u.val.([]tree.SequenceOption) } func (u *sqlSymUnion) expr() tree.Expr { if expr, ok := u.val.(tree.Expr); ok { return expr } return nil } func (u *sqlSymUnion) exprs() tree.Exprs { return u.val.(tree.Exprs) } func (u *sqlSymUnion) selExpr() tree.SelectExpr { return u.val.(tree.SelectExpr) } func (u *sqlSymUnion) selExprs() tree.SelectExprs { return u.val.(tree.SelectExprs) } func (u *sqlSymUnion) retClause() tree.ReturningClause { return u.val.(tree.ReturningClause) } func (u *sqlSymUnion) aliasClause() tree.AliasClause { return u.val.(tree.AliasClause) } func (u *sqlSymUnion) asOfClause() tree.AsOfClause { return u.val.(tree.AsOfClause) } func (u *sqlSymUnion) tblExpr() tree.TableExpr { return u.val.(tree.TableExpr) } func (u *sqlSymUnion) tblExprs() tree.TableExprs { return u.val.(tree.TableExprs) } func (u *sqlSymUnion) from() tree.From { return u.val.(tree.From) } func (u *sqlSymUnion) int32s() []int32 { return u.val.([]int32) } func (u *sqlSymUnion) joinCond() tree.JoinCond { return u.val.(tree.JoinCond) } func (u *sqlSymUnion) when() *tree.When { return u.val.(*tree.When) } func (u *sqlSymUnion) whens() []*tree.When { return u.val.([]*tree.When) } func (u *sqlSymUnion) lockingClause() tree.LockingClause { return u.val.(tree.LockingClause) } func (u *sqlSymUnion) lockingItem() *tree.LockingItem { return u.val.(*tree.LockingItem) } func (u *sqlSymUnion) lockingStrength() tree.LockingStrength { return u.val.(tree.LockingStrength) } func (u *sqlSymUnion) lockingWaitPolicy() tree.LockingWaitPolicy { return u.val.(tree.LockingWaitPolicy) } func (u *sqlSymUnion) updateExpr() *tree.UpdateExpr { return u.val.(*tree.UpdateExpr) } func (u *sqlSymUnion) updateExprs() tree.UpdateExprs { return u.val.(tree.UpdateExprs) } func (u *sqlSymUnion) limit() *tree.Limit { return u.val.(*tree.Limit) } func (u *sqlSymUnion) targetList() tree.TargetList { return u.val.(tree.TargetList) } func (u *sqlSymUnion) targetListPtr() *tree.TargetList { return u.val.(*tree.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() *tree.OnConflict { return u.val.(*tree.OnConflict) } func (u *sqlSymUnion) orderBy() tree.OrderBy { return u.val.(tree.OrderBy) } func (u *sqlSymUnion) order() *tree.Order { return u.val.(*tree.Order) } func (u *sqlSymUnion) orders() []*tree.Order { return u.val.([]*tree.Order) } func (u *sqlSymUnion) groupBy() tree.GroupBy { return u.val.(tree.GroupBy) } func (u *sqlSymUnion) windowFrame() *tree.WindowFrame { return u.val.(*tree.WindowFrame) } func (u *sqlSymUnion) windowFrameBounds() tree.WindowFrameBounds { return u.val.(tree.WindowFrameBounds) } func (u *sqlSymUnion) windowFrameBound() *tree.WindowFrameBound { return u.val.(*tree.WindowFrameBound) } func (u *sqlSymUnion) windowFrameExclusion() tree.WindowFrameExclusion { return u.val.(tree.WindowFrameExclusion) } func (u *sqlSymUnion) distinctOn() tree.DistinctOn { return u.val.(tree.DistinctOn) } func (u *sqlSymUnion) dir() tree.Direction { return u.val.(tree.Direction) } func (u *sqlSymUnion) nullsOrder() tree.NullsOrder { return u.val.(tree.NullsOrder) } func (u *sqlSymUnion) alterTableCmd() tree.AlterTableCmd { return u.val.(tree.AlterTableCmd) } func (u *sqlSymUnion) alterTableCmds() tree.AlterTableCmds { return u.val.(tree.AlterTableCmds) } func (u *sqlSymUnion) alterIndexCmd() tree.AlterIndexCmd { return u.val.(tree.AlterIndexCmd) } func (u *sqlSymUnion) alterIndexCmds() tree.AlterIndexCmds { return u.val.(tree.AlterIndexCmds) } func (u *sqlSymUnion) isoLevel() tree.IsolationLevel { return u.val.(tree.IsolationLevel) } func (u *sqlSymUnion) userPriority() tree.UserPriority { return u.val.(tree.UserPriority) } func (u *sqlSymUnion) readWriteMode() tree.ReadWriteMode { return u.val.(tree.ReadWriteMode) } func (u *sqlSymUnion) idxElem() tree.IndexElem { return u.val.(tree.IndexElem) } func (u *sqlSymUnion) idxElems() tree.IndexElemList { return u.val.(tree.IndexElemList) } func (u *sqlSymUnion) dropBehavior() tree.DropBehavior { return u.val.(tree.DropBehavior) } func (u *sqlSymUnion) validationBehavior() tree.ValidationBehavior { return u.val.(tree.ValidationBehavior) } func (u *sqlSymUnion) interleave() *tree.InterleaveDef { return u.val.(*tree.InterleaveDef) } func (u *sqlSymUnion) partitionBy() *tree.PartitionBy { return u.val.(*tree.PartitionBy) } func (u *sqlSymUnion) createTableOnCommitSetting() tree.CreateTableOnCommitSetting { return u.val.(tree.CreateTableOnCommitSetting) } func (u *sqlSymUnion) listPartition() tree.ListPartition { return u.val.(tree.ListPartition) } func (u *sqlSymUnion) listPartitions() []tree.ListPartition { return u.val.([]tree.ListPartition) } func (u *sqlSymUnion) rangePartition() tree.RangePartition { return u.val.(tree.RangePartition) } func (u *sqlSymUnion) rangePartitions() []tree.RangePartition { return u.val.([]tree.RangePartition) } func (u *sqlSymUnion) setZoneConfig() *tree.SetZoneConfig { return u.val.(*tree.SetZoneConfig) } func (u *sqlSymUnion) tuples() []*tree.Tuple { return u.val.([]*tree.Tuple) } func (u *sqlSymUnion) tuple() *tree.Tuple { return u.val.(*tree.Tuple) } func (u *sqlSymUnion) windowDef() *tree.WindowDef { return u.val.(*tree.WindowDef) } func (u *sqlSymUnion) window() tree.Window { return u.val.(tree.Window) } func (u *sqlSymUnion) op() tree.Operator { return u.val.(tree.Operator) } func (u *sqlSymUnion) cmpOp() tree.ComparisonOperator { return u.val.(tree.ComparisonOperator) } func (u *sqlSymUnion) intervalTypeMetadata() types.IntervalTypeMetadata { return u.val.(types.IntervalTypeMetadata) } func (u *sqlSymUnion) kvOption() tree.KVOption { return u.val.(tree.KVOption) } func (u *sqlSymUnion) kvOptions() []tree.KVOption { if colType, ok := u.val.([]tree.KVOption); ok { return colType } return nil } func (u *sqlSymUnion) transactionModes() tree.TransactionModes { return u.val.(tree.TransactionModes) } func (u *sqlSymUnion) compositeKeyMatchMethod() tree.CompositeKeyMatchMethod { return u.val.(tree.CompositeKeyMatchMethod) } func (u *sqlSymUnion) referenceAction() tree.ReferenceAction { return u.val.(tree.ReferenceAction) } func (u *sqlSymUnion) referenceActions() tree.ReferenceActions { return u.val.(tree.ReferenceActions) } func (u *sqlSymUnion) createStatsOptions() *tree.CreateStatsOptions { return u.val.(*tree.CreateStatsOptions) } func (u *sqlSymUnion) scrubOptions() tree.ScrubOptions { return u.val.(tree.ScrubOptions) } func (u *sqlSymUnion) scrubOption() tree.ScrubOption { return u.val.(tree.ScrubOption) } func (u *sqlSymUnion) resolvableFuncRefFromName() tree.ResolvableFunctionReference { return tree.ResolvableFunctionReference{FunctionReference: u.unresolvedName()} } func (u *sqlSymUnion) rowsFromExpr() *tree.RowsFromExpr { return u.val.(*tree.RowsFromExpr) } func (u *sqlSymUnion) partitionedBackup() tree.PartitionedBackup { return u.val.(tree.PartitionedBackup) } func (u *sqlSymUnion) partitionedBackups() []tree.PartitionedBackup { return u.val.([]tree.PartitionedBackup) } func newNameFromStr(s string) *tree.Name { return (*tree.Name)(&s) } %} // 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 IDENT SCONST BCONST BITCONST %token <*tree.NumVal> ICONST FCONST %token <*tree.Placeholder> PLACEHOLDER %token TYPECAST TYPEANNOTATE DOT_DOT %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS %token NOT_REGMATCH REGIMATCH NOT_REGIMATCH %token 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 ABORT ACTION ADD ADMIN AGGREGATE %token ALL ALTER ANALYSE ANALYZE AND AND_AND ANY ANNOTATE_TYPE ARRAY AS ASC %token ASYMMETRIC AT AUTHORIZATION AUTOMATIC %token BACKUP BEGIN BETWEEN BIGINT BIGSERIAL BIT %token BUCKET_COUNT %token BLOB BOOL BOOLEAN BOTH BUNDLE BY BYTEA BYTES %token CACHE CANCEL CASCADE CASE CAST CHANGEFEED CHAR %token CHARACTER CHARACTERISTICS CHECK %token CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMIT %token COMMITTED COMPACT COMPLETE CONCAT CONCURRENTLY CONFIGURATION CONFIGURATIONS CONFIGURE %token CONFLICT CONSTRAINT CONSTRAINTS CONTAINS CONVERSION COPY COVERING CREATE CREATEROLE %token CROSS CUBE CURRENT CURRENT_CATALOG CURRENT_DATE CURRENT_SCHEMA %token CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP %token CURRENT_USER CYCLE %token DATA DATABASE DATABASES DATE DAY DEC DECIMAL DEFAULT %token DEALLOCATE DEFERRABLE DEFERRED DELETE DESC %token DISCARD DISTINCT DO DOMAIN DOUBLE DROP %token ELSE ENCODING END ENUM ESCAPE EXCEPT EXCLUDE %token EXISTS EXECUTE EXPERIMENTAL %token EXPERIMENTAL_FINGERPRINTS EXPERIMENTAL_REPLICA %token EXPERIMENTAL_AUDIT %token EXPIRATION EXPLAIN EXPORT EXTENSION EXTRACT EXTRACT_DURATION %token FALSE FAMILY FETCH FETCHVAL FETCHTEXT FETCHVAL_PATH FETCHTEXT_PATH %token FILES FILTER %token FIRST FLOAT FLOAT4 FLOAT8 FLOORDIV FOLLOWING FOR FORCE_INDEX FOREIGN FROM FULL FUNCTION %token GLOBAL GRANT GRANTS GREATEST GROUP GROUPING GROUPS %token HAVING HASH HIGH HISTOGRAM HOUR %token IF IFERROR IFNULL IGNORE_FOREIGN_KEYS ILIKE IMMEDIATE IMPORT IN INCLUDE INCREMENT INCREMENTAL %token INET INET_CONTAINED_BY_OR_EQUALS %token INET_CONTAINS_OR_EQUALS INDEX INDEXES INJECT INTERLEAVE INITIALLY %token INNER INSERT INT INT2VECTOR INT2 INT4 INT8 INT64 INTEGER %token INTERSECT INTERVAL INTO INVERTED IS ISERROR ISNULL ISOLATION %token JOB JOBS JOIN JSON JSONB JSON_SOME_EXISTS JSON_ALL_EXISTS %token KEY KEYS KV %token LANGUAGE LAST LATERAL LC_CTYPE LC_COLLATE %token LEADING LEASE LEAST LEFT LESS LEVEL LIKE LIMIT LIST LOCAL %token LOCALTIME LOCALTIMESTAMP LOCKED LOGIN LOOKUP LOW LSHIFT %token MATCH MATERIALIZED MERGE MINVALUE MAXVALUE MINUTE MONTH %token NAN NAME NAMES NATURAL NEXT NO NOCREATEROLE NOLOGIN NO_INDEX_JOIN %token NONE NORMAL NOT NOTHING NOTNULL NOWAIT NULL NULLIF NULLS NUMERIC %token OF OFF OFFSET OID OIDS OIDVECTOR ON ONLY OPT OPTION OPTIONS OR %token ORDER ORDINALITY OTHERS OUT OUTER OVER OVERLAPS OVERLAY OWNED OPERATOR %token PARENT PARTIAL PARTITION PARTITIONS PASSWORD PAUSE PHYSICAL PLACING %token PLAN PLANS POSITION PRECEDING PRECISION PREPARE PRESERVE PRIMARY PRIORITY %token PROCEDURAL PUBLIC PUBLICATION %token QUERIES QUERY %token RANGE RANGES READ REAL RECURSIVE REF REFERENCES %token REGCLASS REGPROC REGPROCEDURE REGNAMESPACE REGTYPE REINDEX %token REMOVE_PATH RENAME REPEATABLE REPLACE %token RELEASE RESET RESTORE RESTRICT RESUME RETURNING REVOKE RIGHT %token ROLE ROLES ROLLBACK ROLLUP ROW ROWS RSHIFT RULE %token SAVEPOINT SCATTER SCHEMA SCHEMAS SCRUB SEARCH SECOND SELECT SEQUENCE SEQUENCES %token SERIAL SERIAL2 SERIAL4 SERIAL8 %token SERIALIZABLE SERVER SESSION SESSIONS SESSION_USER SET SETTING SETTINGS %token SHARE SHOW SIMILAR SIMPLE SKIP SMALLINT SMALLSERIAL SNAPSHOT SOME SPLIT SQL %token START STATISTICS STATUS STDIN STRICT STRING STORE STORED STORING SUBSTRING %token SYMMETRIC SYNTAX SYSTEM SUBSCRIPTION %token TABLE TABLES TEMP TEMPLATE TEMPORARY TESTING_RELOCATE EXPERIMENTAL_RELOCATE TEXT THEN %token TIES TIME TIMETZ TIMESTAMP TIMESTAMPTZ TO THROTTLING TRAILING TRACE TRANSACTION TREAT TRIGGER TRIM TRUE %token TRUNCATE TRUSTED TYPE %token TRACING %token UNBOUNDED UNCOMMITTED UNION UNIQUE UNKNOWN UNLOGGED UNSPLIT %token UPDATE UPSERT UNTIL USE USER USERS USING UUID %token VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VIEW VARYING VIRTUAL %token WHEN WHERE WINDOW WITH WITHIN WITHOUT WORK WRITE %token YEAR %token 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 int32 pos int32 str string union sqlSymUnion } %type stmt_block %type stmt %type alter_stmt %type alter_ddl_stmt %type alter_table_stmt %type alter_index_stmt %type alter_view_stmt %type alter_sequence_stmt %type alter_database_stmt %type alter_range_stmt %type alter_partition_stmt %type alter_role_stmt // ALTER RANGE %type alter_zone_range_stmt // ALTER TABLE %type alter_onetable_stmt %type alter_split_stmt %type alter_unsplit_stmt %type alter_rename_table_stmt %type alter_scatter_stmt %type alter_relocate_stmt %type alter_relocate_lease_stmt %type alter_zone_table_stmt // ALTER PARTITION %type alter_zone_partition_stmt // ALTER DATABASE %type alter_rename_database_stmt %type alter_zone_database_stmt // ALTER INDEX %type alter_oneindex_stmt %type alter_scatter_index_stmt %type alter_split_index_stmt %type alter_unsplit_index_stmt %type alter_rename_index_stmt %type alter_relocate_index_stmt %type alter_relocate_index_lease_stmt %type alter_zone_index_stmt // ALTER VIEW %type alter_rename_view_stmt // ALTER SEQUENCE %type alter_rename_sequence_stmt %type alter_sequence_options_stmt %type backup_stmt %type begin_stmt %type cancel_stmt %type cancel_jobs_stmt %type cancel_queries_stmt %type cancel_sessions_stmt // SCRUB %type scrub_stmt %type scrub_database_stmt %type scrub_table_stmt %type opt_scrub_options_clause %type scrub_option_list %type scrub_option %type comment_stmt %type commit_stmt %type copy_from_stmt %type create_stmt %type create_changefeed_stmt %type create_ddl_stmt %type create_database_stmt %type create_index_stmt %type create_role_stmt %type create_schema_stmt %type create_table_stmt %type create_table_as_stmt %type create_view_stmt %type create_sequence_stmt %type create_stats_stmt %type <*tree.CreateStatsOptions> opt_create_stats_options %type <*tree.CreateStatsOptions> create_stats_option_list %type <*tree.CreateStatsOptions> create_stats_option %type create_type_stmt %type delete_stmt %type discard_stmt %type drop_stmt %type drop_ddl_stmt %type drop_database_stmt %type drop_index_stmt %type drop_role_stmt %type drop_table_stmt %type drop_view_stmt %type drop_sequence_stmt %type explain_stmt %type prepare_stmt %type preparable_stmt %type row_source_extension_stmt %type export_stmt %type execute_stmt %type deallocate_stmt %type grant_stmt %type insert_stmt %type import_stmt %type pause_stmt %type release_stmt %type reset_stmt reset_session_stmt reset_csetting_stmt %type resume_stmt %type restore_stmt %type partitioned_backup %type <[]tree.PartitionedBackup> partitioned_backup_list %type revoke_stmt %type <*tree.Select> select_stmt %type abort_stmt %type rollback_stmt %type savepoint_stmt %type preparable_set_stmt nonpreparable_set_stmt %type set_session_stmt %type set_csetting_stmt %type set_transaction_stmt %type set_exprs_internal %type generic_set %type set_rest_more %type set_names %type show_stmt %type show_backup_stmt %type show_columns_stmt %type show_constraints_stmt %type show_create_stmt %type show_csettings_stmt %type show_databases_stmt %type show_fingerprints_stmt %type show_grants_stmt %type show_histogram_stmt %type show_indexes_stmt %type show_partitions_stmt %type show_jobs_stmt %type show_queries_stmt %type show_ranges_stmt %type show_range_for_row_stmt %type show_roles_stmt %type show_schemas_stmt %type show_sequences_stmt %type show_session_stmt %type show_sessions_stmt %type show_savepoint_stmt %type show_stats_stmt %type show_syntax_stmt %type show_tables_stmt %type show_trace_stmt %type show_transaction_stmt %type show_users_stmt %type show_zone_stmt %type session_var %type <*string> comment_text %type transaction_stmt %type truncate_stmt %type update_stmt %type upsert_stmt %type use_stmt %type reindex_stmt %type <[]string> opt_incremental %type kv_option %type <[]tree.KVOption> kv_option_list opt_with_options var_set_list %type import_format %type storage_parameter %type <[]tree.StorageParam> storage_parameter_list opt_table_with %type <*tree.Select> select_no_parens %type select_clause select_with_parens simple_select values_clause table_clause simple_select_clause %type for_locking_clause opt_for_locking_clause for_locking_items %type <*tree.LockingItem> for_locking_item %type for_locking_strength %type opt_nowait_or_skip %type set_operation %type alter_column_default %type opt_asc_desc %type opt_nulls_order %type alter_table_cmd %type alter_table_cmds %type alter_index_cmd %type alter_index_cmds %type opt_drop_behavior %type opt_interleave_drop_behavior %type opt_validate_behavior %type opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause %type transaction_iso_level %type transaction_user_priority %type transaction_read_mode %type name opt_name opt_name_parens %type privilege savepoint_name %type role_option password_clause valid_until_clause %type subquery_op %type <*tree.UnresolvedName> func_name %type opt_collate %type database_name index_name opt_index_name column_name insert_column_item statistics_name window_name %type family_name opt_family_name table_alias_name constraint_name target_name zone_name partition_name collation_name %type db_object_name_component %type <*tree.UnresolvedObjectName> table_name standalone_index_name sequence_name type_name view_name db_object_name simple_db_object_name complex_db_object_name %type schema_name %type <*tree.UnresolvedName> table_pattern complex_table_pattern %type <*tree.UnresolvedName> column_path prefixed_column_path column_path_with_star %type insert_target create_stats_target %type <*tree.TableIndexName> table_index_name %type table_index_name_list %type math_op %type iso_level %type user_priority %type opt_table_elem_list table_elem_list create_as_opt_col_list create_as_table_defs %type opt_create_table_on_commit %type <*tree.InterleaveDef> opt_interleave %type <*tree.PartitionBy> opt_partition_by partition_by %type partition opt_partition %type list_partition %type <[]tree.ListPartition> list_partitions %type range_partition %type <[]tree.RangePartition> range_partitions %type opt_all_clause %type distinct_clause %type distinct_on_clause %type opt_column_list insert_column_list opt_stats_columns %type sort_clause opt_sort_clause %type <[]*tree.Order> sortby_list %type index_params create_as_params %type name_list privilege_list %type <[]int32> opt_array_bounds %type from_clause %type from_list rowsfrom_list opt_from_list %type table_pattern_list single_table_pattern_list %type table_name_list opt_locked_rels %type expr_list opt_expr_list tuple1_ambiguous_values tuple1_unambiguous_values %type <*tree.Tuple> expr_tuple1_ambiguous expr_tuple_unambiguous %type attrs %type target_list %type set_clause_list %type <*tree.UpdateExpr> set_clause multiple_set_clause %type array_subscripts %type group_clause %type <*tree.Limit> select_limit opt_select_limit %type relation_expr_list %type returning_clause %type opt_using_clause %type <[]tree.SequenceOption> sequence_option_list opt_sequence_option_list %type sequence_option_elem %type all_or_distinct %type with_comment %type join_outer %type join_qual %type join_type %type opt_join_hint %type extract_list %type overlay_list %type position_list %type substr_list %type trim_list %type execute_param_clause %type opt_interval_qualifier interval_qualifier interval_second %type overlay_placing %type opt_unique opt_concurrently opt_cluster %type opt_using_gin_btree %type <*tree.Limit> limit_clause offset_clause opt_limit_clause %type select_fetch_first_value %type row_or_rows %type first_or_next %type insert_rest %type opt_conf_expr opt_col_def_list %type <*tree.OnConflict> on_conflict %type begin_transaction %type transaction_mode_list transaction_mode %type <*tree.ShardedIndexDef> opt_hash_sharded %type opt_storing %type <*tree.ColumnTableDef> column_def %type table_elem %type where_clause opt_where_clause %type <*tree.ArraySubscript> array_subscript %type opt_slice_bound %type <*tree.IndexFlags> opt_index_flags %type <*tree.IndexFlags> index_flags_param %type <*tree.IndexFlags> index_flags_param_list %type a_expr b_expr c_expr d_expr %type substr_from substr_for %type in_expr %type having_clause %type array_expr %type interval_value %type <[]*types.T> type_list prep_type_clause %type array_expr_list %type <*tree.Tuple> row labeled_row %type case_expr case_arg case_default %type <*tree.When> when_clause %type <[]*tree.When> when_clause_list %type sub_type %type numeric_only %type alias_clause opt_alias_clause %type opt_ordinality opt_compact %type <*tree.Order> sortby %type index_elem create_as_param %type table_ref numeric_table_ref func_table %type rowsfrom_list %type rowsfrom_item %type joined_table %type <*tree.UnresolvedObjectName> relation_expr %type table_expr_opt_alias_idx table_name_opt_idx %type target_elem %type <*tree.UpdateExpr> single_set_clause %type as_of_clause opt_as_of_clause %type opt_changefeed_sink %type explain_option_name %type <[]string> explain_option_list %type <*types.T> typename simple_typename const_typename %type opt_timezone %type <*types.T> numeric opt_numeric_modifiers %type <*types.T> opt_float %type <*types.T> character_with_length character_without_length %type <*types.T> const_datetime interval_type %type <*types.T> bit_with_length bit_without_length %type <*types.T> character_base %type <*types.T> postgres_oid %type <*types.T> cast_target %type extract_arg %type opt_varying %type <*tree.NumVal> signed_iconst only_signed_iconst %type <*tree.NumVal> signed_fconst only_signed_fconst %type iconst32 %type signed_iconst64 %type iconst64 %type var_value %type var_list %type var_name %type unrestricted_name type_function_name %type non_reserved_word %type non_reserved_word_or_sconst %type zone_value %type string_or_placeholder %type string_or_placeholder_list %type unreserved_keyword type_func_name_keyword cockroachdb_extra_type_func_name_keyword %type col_name_keyword reserved_keyword cockroachdb_extra_reserved_keyword extra_var_value %type table_constraint constraint_elem create_as_constraint_def create_as_constraint_elem %type index_def %type family_def %type <[]tree.NamedColumnQualification> col_qual_list create_as_col_qual_list %type col_qualification create_as_col_qualification %type col_qualification_elem create_as_col_qualification_elem %type key_match %type reference_actions %type reference_action reference_on_delete reference_on_update %type func_application func_expr_common_subexpr special_function %type func_expr func_expr_windowless %type opt_with %type <*tree.With> with_clause opt_with_clause %type <[]*tree.CTE> cte_list %type <*tree.CTE> common_table_expr %type within_group_clause %type filter_clause %type opt_partition_clause %type window_clause window_definition_list %type <*tree.WindowDef> window_definition over_clause window_specification %type opt_existing_window_name %type <*tree.WindowFrame> opt_frame_clause %type frame_extent %type <*tree.WindowFrameBound> frame_bound %type opt_frame_exclusion %type <[]tree.ColumnID> opt_tableref_col_list tableref_col_list %type targets targets_roles changefeed_targets %type <*tree.TargetList> opt_on_targets_roles %type for_grantee_clause %type privileges %type <[]tree.KVOption> opt_role_options role_options %type audit_mode %type relocate_kw %type <*tree.SetZoneConfig> set_zone_config %type opt_alter_column_using %type opt_temp %type opt_temp_create_table %type role_or_group_or_user // Precedence: lowest to highest %nonassoc VALUES // see value_clause %nonassoc SET // see table_expr_opt_alias_idx %left UNION EXCEPT %left INTERSECT %left OR %left AND %right NOT %nonassoc IS ISNULL NOTNULL // 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 CONTAINS CONTAINED_BY '?' JSON_SOME_EXISTS JSON_ALL_EXISTS %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, // GROUPS to support opt_existing_window_name; and for RANGE, ROWS, GROUPS 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 GROUPS PRECEDING FOLLOWING CUBE ROLLUP %left CONCAT FETCHVAL FETCHTEXT FETCHVAL_PATH FETCHTEXT_PATH REMOVE_PATH // multi-character ops %left '|' %left '#' %left '&' %left LSHIFT RSHIFT INET_CONTAINS_OR_EQUALS INET_CONTAINED_BY_OR_EQUALS AND_AND %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 { sqllex.(*lexer).SetStmt($1.stmt()) } stmt: HELPTOKEN { return helpWith(sqllex, "") } | preparable_stmt // help texts in sub-rule | copy_from_stmt | comment_stmt | execute_stmt // EXTEND WITH HELP: EXECUTE | deallocate_stmt // EXTEND WITH HELP: DEALLOCATE | discard_stmt // EXTEND WITH HELP: DISCARD | grant_stmt // EXTEND WITH HELP: GRANT | prepare_stmt // EXTEND WITH HELP: PREPARE | revoke_stmt // EXTEND WITH HELP: REVOKE | savepoint_stmt // EXTEND WITH HELP: SAVEPOINT | release_stmt // EXTEND WITH HELP: RELEASE | nonpreparable_set_stmt // help texts in sub-rule | transaction_stmt // help texts in sub-rule | reindex_stmt | /* EMPTY */ { $$.val = tree.Statement(nil) } // %Help: ALTER // %Category: Group // %Text: ALTER TABLE, ALTER INDEX, ALTER VIEW, ALTER SEQUENCE, ALTER DATABASE, ALTER USER, ALTER ROLE alter_stmt: alter_ddl_stmt // help texts in sub-rule | alter_role_stmt // EXTEND WITH HELP: ALTER ROLE | ALTER error // SHOW HELP: ALTER alter_ddl_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_sequence_stmt // EXTEND WITH HELP: ALTER SEQUENCE | alter_database_stmt // EXTEND WITH HELP: ALTER DATABASE | alter_range_stmt // EXTEND WITH HELP: ALTER RANGE | alter_partition_stmt // EXTEND WITH HELP: ALTER PARTITION // %Help: ALTER TABLE - change the definition of a table // %Category: DDL // %Text: // ALTER TABLE [IF EXISTS] [, ...] // // Commands: // ALTER TABLE ... ADD [COLUMN] [IF NOT EXISTS] [] // ALTER TABLE ... ADD // ALTER TABLE ... DROP [COLUMN] [IF EXISTS] [RESTRICT | CASCADE] // ALTER TABLE ... DROP CONSTRAINT [IF EXISTS] [RESTRICT | CASCADE] // ALTER TABLE ... ALTER [COLUMN] {SET DEFAULT | DROP DEFAULT} // ALTER TABLE ... ALTER [COLUMN] DROP NOT NULL // ALTER TABLE ... ALTER [COLUMN] DROP STORED // ALTER TABLE ... ALTER [COLUMN] [SET DATA] TYPE [COLLATE ] // ALTER TABLE ... ALTER PRIMARY KEY USING INDEX // ALTER TABLE ... RENAME TO // ALTER TABLE ... RENAME [COLUMN] TO // ALTER TABLE ... VALIDATE CONSTRAINT // ALTER TABLE ... SPLIT AT [WITH EXPIRATION ] // ALTER TABLE ... UNSPLIT AT // ALTER TABLE ... UNSPLIT ALL // ALTER TABLE ... SCATTER [ FROM ( ) TO ( ) ] // ALTER TABLE ... INJECT STATISTICS ... (experimental) // ALTER TABLE ... PARTITION BY RANGE ( ) ( ) // ALTER TABLE ... PARTITION BY LIST ( ) ( ) // ALTER TABLE ... PARTITION BY NOTHING // ALTER TABLE ... CONFIGURE ZONE // // Column qualifiers: // [CONSTRAINT ] {NULL | NOT NULL | UNIQUE | PRIMARY KEY | CHECK () | DEFAULT } // FAMILY , CREATE [IF NOT EXISTS] FAMILY [] // REFERENCES [( )] // COLLATE // // Zone configurations: // DISCARD // USING = [, ...] // USING = COPY FROM PARENT [, ...] // { TO | = } // // %SeeAlso: WEBDOCS/alter-table.html alter_table_stmt: alter_onetable_stmt | alter_relocate_stmt | alter_relocate_lease_stmt | alter_split_stmt | alter_unsplit_stmt | alter_scatter_stmt | alter_zone_table_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 PARTITION - apply zone configurations to a partition // %Category: DDL // %Text: // ALTER PARTITION // // Commands: // -- Alter a single partition which exists on any of a table's indexes. // ALTER PARTITION OF TABLE CONFIGURE ZONE // // -- Alter a partition of a specific index. // ALTER PARTITION OF INDEX @ CONFIGURE ZONE // // -- Alter all partitions with the same name across a table's indexes. // ALTER PARTITION OF INDEX @* CONFIGURE ZONE // // Zone configurations: // DISCARD // USING = [, ...] // USING = COPY FROM PARENT [, ...] // { TO | = } // // %SeeAlso: WEBDOCS/configure-zone.html alter_partition_stmt: alter_zone_partition_stmt | ALTER PARTITION error // SHOW HELP: ALTER PARTITION // %Help: ALTER VIEW - change the definition of a view // %Category: DDL // %Text: // ALTER VIEW [IF EXISTS] RENAME TO // %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 SEQUENCE - change the definition of a sequence // %Category: DDL // %Text: // ALTER SEQUENCE [IF EXISTS] // [INCREMENT ] // [MINVALUE | NO MINVALUE] // [MAXVALUE | NO MAXVALUE] // [START ] // [[NO] CYCLE] // ALTER SEQUENCE [IF EXISTS] RENAME TO alter_sequence_stmt: alter_rename_sequence_stmt | alter_sequence_options_stmt | ALTER SEQUENCE error // SHOW HELP: ALTER SEQUENCE alter_sequence_options_stmt: ALTER SEQUENCE sequence_name sequence_option_list { $$.val = &tree.AlterSequence{Name: $3.unresolvedObjectName(), Options: $4.seqOpts(), IfExists: false} } | ALTER SEQUENCE IF EXISTS sequence_name sequence_option_list { $$.val = &tree.AlterSequence{Name: $5.unresolvedObjectName(), Options: $6.seqOpts(), IfExists: true} } // %Help: ALTER DATABASE - change the definition of a database // %Category: DDL // %Text: // ALTER DATABASE RENAME TO // %SeeAlso: WEBDOCS/alter-database.html alter_database_stmt: alter_rename_database_stmt | alter_zone_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 RANGE - change the parameters of a range // %Category: DDL // %Text: // ALTER RANGE // // Commands: // ALTER RANGE ... CONFIGURE ZONE // // Zone configurations: // DISCARD // USING = [, ...] // USING = COPY FROM PARENT [, ...] // { TO | = } // // %SeeAlso: ALTER TABLE alter_range_stmt: alter_zone_range_stmt | ALTER RANGE error // SHOW HELP: ALTER RANGE // %Help: ALTER INDEX - change the definition of an index // %Category: DDL // %Text: // ALTER INDEX [IF EXISTS] // // Commands: // ALTER INDEX ... RENAME TO // ALTER INDEX ... SPLIT AT [WITH EXPIRATION ] // ALTER INDEX ... UNSPLIT AT // ALTER INDEX ... UNSPLIT ALL // ALTER INDEX ... SCATTER [ FROM ( ) TO ( ) ] // // Zone configurations: // DISCARD // USING = [, ...] // USING = COPY FROM PARENT [, ...] // { TO | = } // // %SeeAlso: WEBDOCS/alter-index.html alter_index_stmt: alter_oneindex_stmt | alter_relocate_index_stmt | alter_relocate_index_lease_stmt | alter_split_index_stmt | alter_unsplit_index_stmt | alter_scatter_index_stmt | alter_rename_index_stmt | alter_zone_index_stmt // ALTER INDEX has its error help token here because the ALTER INDEX // prefix is spread over multiple non-terminals. | ALTER INDEX error // SHOW HELP: ALTER INDEX alter_onetable_stmt: ALTER TABLE relation_expr alter_table_cmds { $$.val = &tree.AlterTable{Table: $3.unresolvedObjectName(), IfExists: false, Cmds: $4.alterTableCmds()} } | ALTER TABLE IF EXISTS relation_expr alter_table_cmds { $$.val = &tree.AlterTable{Table: $5.unresolvedObjectName(), IfExists: true, Cmds: $6.alterTableCmds()} } alter_oneindex_stmt: ALTER INDEX table_index_name alter_index_cmds { $$.val = &tree.AlterIndex{Index: $3.tableIndexName(), IfExists: false, Cmds: $4.alterIndexCmds()} } | ALTER INDEX IF EXISTS table_index_name alter_index_cmds { $$.val = &tree.AlterIndex{Index: $5.tableIndexName(), IfExists: true, Cmds: $6.alterIndexCmds()} } alter_split_stmt: ALTER TABLE table_name SPLIT AT select_stmt { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Split{ TableOrIndex: tree.TableIndexName{Table: name}, Rows: $6.slct(), ExpireExpr: tree.Expr(nil), } } | ALTER TABLE table_name SPLIT AT select_stmt WITH EXPIRATION a_expr { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Split{ TableOrIndex: tree.TableIndexName{Table: name}, Rows: $6.slct(), ExpireExpr: $9.expr(), } } alter_split_index_stmt: ALTER INDEX table_index_name SPLIT AT select_stmt { $$.val = &tree.Split{TableOrIndex: $3.tableIndexName(), Rows: $6.slct(), ExpireExpr: tree.Expr(nil)} } | ALTER INDEX table_index_name SPLIT AT select_stmt WITH EXPIRATION a_expr { $$.val = &tree.Split{TableOrIndex: $3.tableIndexName(), Rows: $6.slct(), ExpireExpr: $9.expr()} } alter_unsplit_stmt: ALTER TABLE table_name UNSPLIT AT select_stmt { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Unsplit{ TableOrIndex: tree.TableIndexName{Table: name}, Rows: $6.slct(), } } | ALTER TABLE table_name UNSPLIT ALL { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Unsplit { TableOrIndex: tree.TableIndexName{Table: name}, All: true, } } alter_unsplit_index_stmt: ALTER INDEX table_index_name UNSPLIT AT select_stmt { $$.val = &tree.Unsplit{TableOrIndex: $3.tableIndexName(), Rows: $6.slct()} } | ALTER INDEX table_index_name UNSPLIT ALL { $$.val = &tree.Unsplit{TableOrIndex: $3.tableIndexName(), All: true} } relocate_kw: TESTING_RELOCATE | EXPERIMENTAL_RELOCATE alter_relocate_stmt: ALTER TABLE table_name relocate_kw select_stmt { /* SKIP DOC */ name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Relocate{ TableOrIndex: tree.TableIndexName{Table: name}, Rows: $5.slct(), } } alter_relocate_index_stmt: ALTER INDEX table_index_name relocate_kw select_stmt { /* SKIP DOC */ $$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $5.slct()} } alter_relocate_lease_stmt: ALTER TABLE table_name relocate_kw LEASE select_stmt { /* SKIP DOC */ name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Relocate{ TableOrIndex: tree.TableIndexName{Table: name}, Rows: $6.slct(), RelocateLease: true, } } alter_relocate_index_lease_stmt: ALTER INDEX table_index_name relocate_kw LEASE select_stmt { /* SKIP DOC */ $$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $6.slct(), RelocateLease: true} } alter_zone_range_stmt: ALTER RANGE zone_name set_zone_config { s := $4.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{NamedZone: tree.UnrestrictedName($3)} $$.val = s } set_zone_config: CONFIGURE ZONE to_or_eq a_expr { /* SKIP DOC */ $$.val = &tree.SetZoneConfig{YAMLConfig: $4.expr()} } | CONFIGURE ZONE USING var_set_list { $$.val = &tree.SetZoneConfig{Options: $4.kvOptions()} } | CONFIGURE ZONE USING DEFAULT { /* SKIP DOC */ $$.val = &tree.SetZoneConfig{SetDefault: true} } | CONFIGURE ZONE DISCARD { $$.val = &tree.SetZoneConfig{YAMLConfig: tree.DNull} } alter_zone_database_stmt: ALTER DATABASE database_name set_zone_config { s := $4.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{Database: tree.Name($3)} $$.val = s } alter_zone_table_stmt: ALTER TABLE table_name set_zone_config { name := $3.unresolvedObjectName().ToTableName() s := $4.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{ TableOrIndex: tree.TableIndexName{Table: name}, } $$.val = s } alter_zone_index_stmt: ALTER INDEX table_index_name set_zone_config { s := $4.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{ TableOrIndex: $3.tableIndexName(), } $$.val = s } alter_zone_partition_stmt: ALTER PARTITION partition_name OF TABLE table_name set_zone_config { name := $6.unresolvedObjectName().ToTableName() s := $7.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{ TableOrIndex: tree.TableIndexName{Table: name}, Partition: tree.Name($3), } $$.val = s } | ALTER PARTITION partition_name OF INDEX table_index_name set_zone_config { s := $7.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{ TableOrIndex: $6.tableIndexName(), Partition: tree.Name($3), } $$.val = s } | ALTER PARTITION partition_name OF INDEX table_name '@' '*' set_zone_config { name := $6.unresolvedObjectName().ToTableName() s := $9.setZoneConfig() s.ZoneSpecifier = tree.ZoneSpecifier{ TableOrIndex: tree.TableIndexName{Table: name}, Partition: tree.Name($3), } s.AllIndexes = true $$.val = s } | ALTER PARTITION partition_name OF TABLE table_name '@' error { err := errors.New("index name should not be specified in ALTER PARTITION ... OF TABLE") err = errors.WithHint(err, "try ALTER PARTITION ... OF INDEX") return setErr(sqllex, err) } | ALTER PARTITION partition_name OF TABLE table_name '@' '*' error { err := errors.New("index wildcard unsupported in ALTER PARTITION ... OF TABLE") err = errors.WithHint(err, "try ALTER PARTITION OF INDEX @*") return setErr(sqllex, err) } var_set_list: var_name '=' COPY FROM PARENT { $$.val = []tree.KVOption{tree.KVOption{Key: tree.Name(strings.Join($1.strs(), "."))}} } | var_name '=' var_value { $$.val = []tree.KVOption{tree.KVOption{Key: tree.Name(strings.Join($1.strs(), ".")), Value: $3.expr()}} } | var_set_list ',' var_name '=' var_value { $$.val = append($1.kvOptions(), tree.KVOption{Key: tree.Name(strings.Join($3.strs(), ".")), Value: $5.expr()}) } | var_set_list ',' var_name '=' COPY FROM PARENT { $$.val = append($1.kvOptions(), tree.KVOption{Key: tree.Name(strings.Join($3.strs(), "."))}) } alter_scatter_stmt: ALTER TABLE table_name SCATTER { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Scatter{TableOrIndex: tree.TableIndexName{Table: name}} } | ALTER TABLE table_name SCATTER FROM '(' expr_list ')' TO '(' expr_list ')' { name := $3.unresolvedObjectName().ToTableName() $$.val = &tree.Scatter{ TableOrIndex: tree.TableIndexName{Table: name}, From: $7.exprs(), To: $11.exprs(), } } alter_scatter_index_stmt: ALTER INDEX table_index_name SCATTER { $$.val = &tree.Scatter{TableOrIndex: $3.tableIndexName()} } | ALTER INDEX table_index_name SCATTER FROM '(' expr_list ')' TO '(' expr_list ')' { $$.val = &tree.Scatter{TableOrIndex: $3.tableIndexName(), From: $7.exprs(), To: $11.exprs()} } alter_table_cmds: alter_table_cmd { $$.val = tree.AlterTableCmds{$1.alterTableCmd()} } | alter_table_cmds ',' alter_table_cmd { $$.val = append($1.alterTableCmds(), $3.alterTableCmd()) } alter_table_cmd: // ALTER TABLE RENAME [COLUMN] TO RENAME opt_column column_name TO column_name { $$.val = &tree.AlterTableRenameColumn{Column: tree.Name($3), NewName: tree.Name($5) } } // ALTER TABLE RENAME CONSTRAINT TO | RENAME CONSTRAINT column_name TO column_name { $$.val = &tree.AlterTableRenameConstraint{Constraint: tree.Name($3), NewName: tree.Name($5) } } // ALTER TABLE ADD | ADD column_def { $$.val = &tree.AlterTableAddColumn{IfNotExists: false, ColumnDef: $2.colDef()} } // ALTER TABLE ADD IF NOT EXISTS | ADD IF NOT EXISTS column_def { $$.val = &tree.AlterTableAddColumn{IfNotExists: true, ColumnDef: $5.colDef()} } // ALTER TABLE ADD COLUMN | ADD COLUMN column_def { $$.val = &tree.AlterTableAddColumn{IfNotExists: false, ColumnDef: $3.colDef()} } // ALTER TABLE ADD COLUMN IF NOT EXISTS | ADD COLUMN IF NOT EXISTS column_def { $$.val = &tree.AlterTableAddColumn{IfNotExists: true, ColumnDef: $6.colDef()} } // ALTER TABLE ALTER [COLUMN] {SET DEFAULT |DROP DEFAULT} | ALTER opt_column column_name alter_column_default { $$.val = &tree.AlterTableSetDefault{Column: tree.Name($3), Default: $4.expr()} } // ALTER TABLE ALTER [COLUMN] DROP NOT NULL | ALTER opt_column column_name DROP NOT NULL { $$.val = &tree.AlterTableDropNotNull{Column: tree.Name($3)} } // ALTER TABLE ALTER [COLUMN] DROP STORED | ALTER opt_column column_name DROP STORED { $$.val = &tree.AlterTableDropStored{Column: tree.Name($3)} } // ALTER TABLE ALTER [COLUMN] SET NOT NULL | ALTER opt_column column_name SET NOT NULL { $$.val = &tree.AlterTableSetNotNull{Column: tree.Name($3)} } // ALTER TABLE DROP [COLUMN] IF EXISTS [RESTRICT|CASCADE] | DROP opt_column IF EXISTS column_name opt_drop_behavior { $$.val = &tree.AlterTableDropColumn{ IfExists: true, Column: tree.Name($5), DropBehavior: $6.dropBehavior(), } } // ALTER TABLE DROP [COLUMN] [RESTRICT|CASCADE] | DROP opt_column column_name opt_drop_behavior { $$.val = &tree.AlterTableDropColumn{ IfExists: false, Column: tree.Name($3), DropBehavior: $4.dropBehavior(), } } // ALTER TABLE ALTER [COLUMN] // [SET DATA] TYPE // [ COLLATE collation ] // [ USING ] | ALTER opt_column column_name opt_set_data TYPE typename opt_collate opt_alter_column_using { $$.val = &tree.AlterTableAlterColumnType{ Column: tree.Name($3), ToType: $6.colType(), Collation: $7, Using: $8.expr(), } } // ALTER TABLE ADD CONSTRAINT ... | ADD table_constraint opt_validate_behavior { $$.val = &tree.AlterTableAddConstraint{ ConstraintDef: $2.constraintDef(), ValidationBehavior: $3.validationBehavior(), } } // ALTER TABLE ALTER CONSTRAINT ... | ALTER CONSTRAINT constraint_name error { return unimplementedWithIssueDetail(sqllex, 31632, "alter constraint") } // ALTER TABLE VALIDATE CONSTRAINT ... // ALTER TABLE ALTER PRIMARY KEY USING INDEX | ALTER PRIMARY KEY USING COLUMNS '(' index_params ')' opt_hash_sharded opt_interleave { $$.val = &tree.AlterTableAlterPrimaryKey{ Columns: $7.idxElems(), Sharded: $9.shardedIndexDef(), Interleave: $10.interleave(), } } | VALIDATE CONSTRAINT constraint_name { $$.val = &tree.AlterTableValidateConstraint{ Constraint: tree.Name($3), } } // ALTER TABLE DROP CONSTRAINT IF EXISTS [RESTRICT|CASCADE] | DROP CONSTRAINT IF EXISTS constraint_name opt_drop_behavior { $$.val = &tree.AlterTableDropConstraint{ IfExists: true, Constraint: tree.Name($5), DropBehavior: $6.dropBehavior(), } } // ALTER TABLE DROP CONSTRAINT [RESTRICT|CASCADE] | DROP CONSTRAINT constraint_name opt_drop_behavior { $$.val = &tree.AlterTableDropConstraint{ IfExists: false, Constraint: tree.Name($3), DropBehavior: $4.dropBehavior(), } } // ALTER TABLE EXPERIMENTAL_AUDIT SET | EXPERIMENTAL_AUDIT SET audit_mode { $$.val = &tree.AlterTableSetAudit{Mode: $3.auditMode()} } // ALTER TABLE PARTITION BY ... | partition_by { $$.val = &tree.AlterTablePartitionBy{ PartitionBy: $1.partitionBy(), } } // ALTER TABLE INJECT STATISTICS | INJECT STATISTICS a_expr { /* SKIP DOC */ $$.val = &tree.AlterTableInjectStats{ Stats: $3.expr(), } } audit_mode: READ WRITE { $$.val = tree.AuditModeReadWrite } | OFF { $$.val = tree.AuditModeDisable } alter_index_cmds: alter_index_cmd { $$.val = tree.AlterIndexCmds{$1.alterIndexCmd()} } | alter_index_cmds ',' alter_index_cmd { $$.val = append($1.alterIndexCmds(), $3.alterIndexCmd()) } alter_index_cmd: partition_by { $$.val = &tree.AlterIndexPartitionBy{ PartitionBy: $1.partitionBy(), } } alter_column_default: SET DEFAULT a_expr { $$.val = $3.expr() } | DROP DEFAULT { $$.val = nil } opt_alter_column_using: USING a_expr { $$.val = $2.expr() } | /* EMPTY */ { $$.val = nil } opt_drop_behavior: CASCADE { $$.val = tree.DropCascade } | RESTRICT { $$.val = tree.DropRestrict } | /* EMPTY */ { $$.val = tree.DropDefault } opt_validate_behavior: NOT VALID { $$.val = tree.ValidationSkip } | /* EMPTY */ { $$.val = tree.ValidationDefault } // %Help: BACKUP - back up data to external storage // %Category: CCL // %Text: // BACKUP TO // [ AS OF SYSTEM TIME ] // [ INCREMENTAL FROM ] // [ WITH