sql: permit designating a primary key in CREATE TABLE AS #20940
Labels
A-schema-changes
A-sql-semantics
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Currently,
CREATE TABLE AS
does not allow the user to specify primary key columns for the new table. This is a major limitation because CockroachDB doesn't allow users to change the primary key of a table, unlike in PostgreSQL. PostgreSQL can get away with having no syntax for this because it's no big deal for them to add a primary key later.We should resolve this limitation by extending the grammar to allow specifying primary key columns.
Currently, the grammar is defined as:
CREATE TABLE any_name opt_column_list AS select_stmt
The
opt_column_list
production should be replaced with one that permitsname
,index_def
,family_def
, andtable_constraint
- basically exactly what's permitted in an ordinaryCREATE TABLE
expression, except replacing the column definition syntax (a INT NOT NULL
) with column names only (a
).The text was updated successfully, but these errors were encountered: