-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Check constraint #542
Check constraint #542
Conversation
@LemarAb hello! As it was written here (#536 (comment)) - we want to express this with |
src/expr.rs
Outdated
@@ -37,6 +37,7 @@ pub enum SimpleExpr { | |||
AsEnum(DynIden, Box<SimpleExpr>), | |||
Case(Box<CaseStatement>), | |||
Constant(Value), | |||
Check(String), |
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.
Hey @LemarAb, thanks for contributing!!
We should represent the check expression with SimpleExpr
.
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.
@billy1624, hey. We have already talked about it in Discord.
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.
From Discord:
#[derive(Debug, Clone)]
pub enum ColumnSpec {
Null,
NotNull,
Default(SimpleExpr),
AutoIncrement,
UniqueKey,
PrimaryKey,
Check(SimpleExpr),
Extra(String),
}
I now have added check as SimpleExpr (yet to push), however, I was wondering what scope this issue covers: Should you also be able to drop / alter check constraints or is check constraints on creation sufficient for now? |
I think in this PR we can simply focus on the creation of check constraint. |
Obviously, there is still a merge conflict present, but I will preferably fix it once a review is concluded to not make unnecessary changes. Also, I was forced to add 'alter add check' to Postgres, otherwise compilation would have failed. |
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.
Just found that the correct syntax for a check constraint is CHECK ( ... )
. i.e. with parentheses.
CREATE TABLE glyph
(
id int NOT NULL,
aspect int NOT NULL CHECK (aspect = 0),
CHECK (id > aspect),
CHECK (id >= aspect)
)
- Postgres: https://dbfiddle.uk/bewF6HT6
- MySQL: https://dbfiddle.uk/icD_zHT-
- MariaDB: https://dbfiddle.uk/4tGMgaAq
- SQLite: https://dbfiddle.uk/8Tynj0mh
src/table/create.rs
Outdated
@@ -84,6 +85,7 @@ pub struct TableCreateStatement { | |||
pub(crate) indexes: Vec<IndexCreateStatement>, | |||
pub(crate) foreign_keys: Vec<ForeignKeyCreateStatement>, | |||
pub(crate) if_not_exists: bool, | |||
pub(crate) check: Option<SimpleExpr>, |
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.
Can we allow multiple check constraint at table level?
pub(crate) check: Option<SimpleExpr>, | |
pub(crate) checks: Vec<SimpleExpr>, |
4dcbfa2
to
190d2e9
Compare
Hey @LemarAb, could you please resolve the conflict, CI tests won't be executed otherwise |
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.
Hey @LemarAb, thanks again for the contributions!!
I'd like to merge this into a local branch and make changes to it.
🎉 Released In 0.29.1 🎉Thank you everyone for the contribution! |
PR Info
CHECK
Constraints #397>New Features
Add check constraint on table alter statement