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

Check constraint #542

Merged
merged 9 commits into from
Dec 23, 2022
Merged

Conversation

LemarAb
Copy link
Contributor

@LemarAb LemarAb commented Dec 4, 2022

PR Info

New Features

  • Create check constraint on column definition and table,
    Add check constraint on table alter statement

@ikrivosheev
Copy link
Member

@LemarAb hello! As it was written here (#536 (comment)) - we want to express this with SimpleExpr

@billy1624 billy1624 linked an issue Dec 7, 2022 that may be closed by this pull request
src/expr.rs Outdated
@@ -37,6 +37,7 @@ pub enum SimpleExpr {
AsEnum(DynIden, Box<SimpleExpr>),
Case(Box<CaseStatement>),
Constant(Value),
Check(String),
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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),
}

@LemarAb
Copy link
Contributor Author

LemarAb commented Dec 14, 2022

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?

@billy1624
Copy link
Member

I think in this PR we can simply focus on the creation of check constraint.

@LemarAb
Copy link
Contributor Author

LemarAb commented Dec 15, 2022

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.

Copy link
Member

@billy1624 billy1624 left a 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)
)

@@ -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>,
Copy link
Member

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?

Suggested change
pub(crate) check: Option<SimpleExpr>,
pub(crate) checks: Vec<SimpleExpr>,

@billy1624
Copy link
Member

Hey @LemarAb, could you please resolve the conflict, CI tests won't be executed otherwise

@billy1624 billy1624 changed the base branch from master to check_constraint December 23, 2022 07:12
Copy link
Member

@billy1624 billy1624 left a 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.

@billy1624 billy1624 merged commit 76e1ef7 into SeaQL:check_constraint Dec 23, 2022
@billy1624 billy1624 mentioned this pull request Dec 23, 2022
2 tasks
@github-actions
Copy link

🎉 Released In 0.29.1 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

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

Successfully merging this pull request may close these issues.

Support Table CHECK Constraints
3 participants