forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: Adds new grammar to support user specified PK in CTAS query.
This change adds grammar rules to support users specifying the primary key columns in a CREATE TABLE...AS query. It allows for both column level qualification, as well as constraint style declaration of PKs. eg: CREATE TABLE a (id PRIMARY KEY) AS SELECT * FROM b CREATE TABLE a (id, PRIMARY KEY(id)) AS SELECT * FROM b CREATE TABLE a (id, idtwo, PRIMARY KEY(id, idtwo)) AS SELECT * FROM b Due to CREATE TABLE and CREATE TABLE ... AS having an identical syntax for declaring PKs, the logic resolving qualifiers and/or constraints had to be pushed to after a column_name without a type is encountered. This avoids reduce/reduce conflicts, but introduces a restriction that a PRIMARY KEY constraint must be preceded by at least one column name. Release note (sql change): Allows user defined PK in CTAS statements.
- Loading branch information
1 parent
5d37afc
commit a111dac
Showing
4 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
create_table_as_stmt ::= | ||
'CREATE' 'TABLE' table_name '(' name ( ( ',' name ) )* ')' 'AS' select_stmt | ||
| 'CREATE' 'TABLE' table_name 'AS' select_stmt | ||
| 'CREATE' 'TABLE' 'IF' 'NOT' 'EXISTS' table_name '(' name ( ( ',' name ) )* ')' 'AS' select_stmt | ||
| 'CREATE' 'TABLE' 'IF' 'NOT' 'EXISTS' table_name 'AS' select_stmt | ||
'CREATE' 'TABLE' table_name create_as_opt_col_list 'AS' select_stmt | ||
| 'CREATE' 'TABLE' 'IF' 'NOT' 'EXISTS' table_name create_as_opt_col_list 'AS' select_stmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters