Skip to content

Commit f503455

Browse files
committed
Add ENFORCED/NOT ENFORCED support for column-level CHECK constraints
1 parent 6550ec8 commit f503455

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/parser/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8911,11 +8911,20 @@ impl<'a> Parser<'a> {
89118911
// since `CHECK` requires parentheses, we can parse the inner expression in ParserState::Normal
89128912
let expr: Expr = self.with_state(ParserState::Normal, |p| p.parse_expr())?;
89138913
self.expect_token(&Token::RParen)?;
8914+
8915+
let enforced = if self.parse_keyword(Keyword::ENFORCED) {
8916+
Some(true)
8917+
} else if self.parse_keywords(&[Keyword::NOT, Keyword::ENFORCED]) {
8918+
Some(false)
8919+
} else {
8920+
None
8921+
};
8922+
89148923
Ok(Some(
89158924
CheckConstraint {
89168925
name: None, // Column-level check constraints don't have names
89178926
expr: Box::new(expr),
8918-
enforced: None, // Could be extended later to support MySQL ENFORCED/NOT ENFORCED
8927+
enforced,
89198928
}
89208929
.into(),
89218930
))

tests/sqlparser_common.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16834,6 +16834,15 @@ fn check_enforced() {
1683416834
);
1683516835
}
1683616836

16837+
#[test]
16838+
fn column_check_enforced() {
16839+
all_dialects().verified_stmt("CREATE TABLE t (x INT CHECK (x > 1) NOT ENFORCED)");
16840+
all_dialects().verified_stmt("CREATE TABLE t (x INT CHECK (x > 1) ENFORCED)");
16841+
all_dialects().verified_stmt(
16842+
"CREATE TABLE t (a INT CHECK (a > 0) NOT ENFORCED, b INT CHECK (b > 0) ENFORCED, c INT CHECK (c > 0))",
16843+
);
16844+
}
16845+
1683716846
#[test]
1683816847
fn join_precedence() {
1683916848
all_dialects_except(|d| !d.supports_left_associative_joins_without_parens())

0 commit comments

Comments
 (0)