Skip to content

Commit a957bb7

Browse files
committed
feat(parser): parse EXCLUDE constraints in CREATE TABLE and ALTER TABLE
1 parent d266014 commit a957bb7

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/parser/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9915,6 +9915,50 @@ impl<'a> Parser<'a> {
99159915
.into(),
99169916
))
99179917
}
9918+
Token::Word(w) if w.keyword == Keyword::EXCLUDE => {
9919+
let index_method = if self.parse_keyword(Keyword::USING) {
9920+
Some(self.parse_identifier()?)
9921+
} else {
9922+
None
9923+
};
9924+
9925+
self.expect_token(&Token::LParen)?;
9926+
let elements =
9927+
self.parse_comma_separated(|p| p.parse_exclusion_element())?;
9928+
self.expect_token(&Token::RParen)?;
9929+
9930+
let include = if self.parse_keyword(Keyword::INCLUDE) {
9931+
self.expect_token(&Token::LParen)?;
9932+
let cols = self.parse_comma_separated(|p| p.parse_identifier())?;
9933+
self.expect_token(&Token::RParen)?;
9934+
cols
9935+
} else {
9936+
vec![]
9937+
};
9938+
9939+
let where_clause = if self.parse_keyword(Keyword::WHERE) {
9940+
self.expect_token(&Token::LParen)?;
9941+
let predicate = self.parse_expr()?;
9942+
self.expect_token(&Token::RParen)?;
9943+
Some(Box::new(predicate))
9944+
} else {
9945+
None
9946+
};
9947+
9948+
let characteristics = self.parse_constraint_characteristics()?;
9949+
9950+
Ok(Some(
9951+
ExclusionConstraint {
9952+
name,
9953+
index_method,
9954+
elements,
9955+
include,
9956+
where_clause,
9957+
characteristics,
9958+
}
9959+
.into(),
9960+
))
9961+
}
99189962
_ => {
99199963
if name.is_some() {
99209964
self.expected("PRIMARY, UNIQUE, FOREIGN, or CHECK", next_token)
@@ -9926,6 +9970,14 @@ impl<'a> Parser<'a> {
99269970
}
99279971
}
99289972

9973+
fn parse_exclusion_element(&mut self) -> Result<ExclusionElement, ParserError> {
9974+
let expr = self.parse_expr()?;
9975+
self.expect_keyword_is(Keyword::WITH)?;
9976+
let operator_token = self.next_token();
9977+
let operator = operator_token.token.to_string();
9978+
Ok(ExclusionElement { expr, operator })
9979+
}
9980+
99299981
fn parse_optional_nulls_distinct(&mut self) -> Result<NullsDistinctOption, ParserError> {
99309982
Ok(if self.parse_keyword(Keyword::NULLS) {
99319983
let not = self.parse_keyword(Keyword::NOT);

0 commit comments

Comments
 (0)