Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: Adds new grammar to support user specified PK in CTAS query. #38884

Closed

Conversation

adityamaru27
Copy link
Contributor

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

@adityamaru27 adityamaru27 requested review from dt and a team July 15, 2019 20:59
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@dt dt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt)

@adityamaru27
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 15, 2019

Build failed

@adityamaru27 adityamaru27 force-pushed the grammer-change-for-pk branch from 73056be to 7d77555 Compare July 15, 2019 21:32
@adityamaru27 adityamaru27 requested a review from a team July 15, 2019 21:32
This change adds grammar rules to support users specifying the
primary key columns in a CREATE TABLE...AS query. It is a subset of
the grammar which is used by a normal CREATE TABLE query, without
having to specify the types for each of the columns in the new table.

Release note: sql change
@adityamaru27 adityamaru27 force-pushed the grammer-change-for-pk branch from 7d77555 to 3fd121a Compare July 15, 2019 21:33
@adityamaru27
Copy link
Contributor Author

Merged as part of #38589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants