-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: support primary key alternate syntax #7160
Changes from all commits
4e7d54e
835de70
4aa727d
78e0b8c
81f44d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,49 @@ CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0])] | |
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
|
||
let sql = "create table person (id int primary key, name string)"; | ||
let plan = r#" | ||
CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0])] | ||
EmptyRelation | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
|
||
let sql = | ||
"create table person (id int, name string unique not null, primary key(id))"; | ||
let plan = r#" | ||
CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0]), Unique([1])] | ||
EmptyRelation | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
|
||
let sql = "create table person (id int, name varchar, primary key(name, id));"; | ||
let plan = r#" | ||
CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([1, 0])] | ||
EmptyRelation | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
} | ||
|
||
#[test] | ||
fn plan_create_table_with_multi_pk() { | ||
let sql = "create table person (id int, name string primary key, primary key(id))"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this means a multi part primary key -- postgres errors on this syntax postgres=# create table person (id int, name varchar primary key, primary key(id));
ERROR: multiple primary keys for table "person" are not allowed
LINE 1: ...e table person (id int, name varchar primary key, primary ke... I think the way this is supposed to be expressed is like create table person (id int, name varchar, primary key(name, id)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess it is better to follow postgres in this case. Postgres supports multiple unique constraints. Hence following query create table person (id int, name string primary key, primary key(id)) can be written as create table person (id int, name string unique not null, primary key(id)) to define unique constraint. For writing composite primary key one have to use following syntax create table person (id int, name varchar, primary key(name, id)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @parkma99 is this comment still outstanding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I am at home this week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no worries and no pressure! I was just trying to understand what the state of this PR was -- it looks like you are aware of the feedback and just haven't had a chance to implement it. I wanted to make sure you weren't waiting on additional feedback I'll mark it as draft so it doesn't appear on the list of PRs needing review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think two primary keys on the same column doesn't really make sense, but we can always make this check more strict as a follow on PR I think |
||
let plan = r#" | ||
CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0]), PrimaryKey([1])] | ||
EmptyRelation | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
} | ||
|
||
#[test] | ||
fn plan_create_table_with_unique() { | ||
let sql = "create table person (id int unique, name string)"; | ||
let plan = "CreateMemoryTable: Bare { table: \"person\" } constraints=[Unique([0])]\n EmptyRelation"; | ||
quick_test(sql, plan); | ||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding unique constraints as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a test case about unique constraints.