Skip to content

Commit b6c0ed4

Browse files
yoavcloudayman-sigma
authored andcommitted
Add support for the SQL OVERLAPS predicate (apache#1638)
1 parent 648fc44 commit b6c0ed4

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/ast/operator.rs

+6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ pub enum BinaryOperator {
248248
/// See [CREATE OPERATOR](https://www.postgresql.org/docs/current/sql-createoperator.html)
249249
/// for more information.
250250
PGCustomBinaryOperator(Vec<String>),
251+
/// The `OVERLAPS` operator
252+
///
253+
/// Specifies a test for an overlap between two datetime periods:
254+
/// <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#overlaps-predicate>
255+
Overlaps,
251256
}
252257

253258
impl fmt::Display for BinaryOperator {
@@ -304,6 +309,7 @@ impl fmt::Display for BinaryOperator {
304309
BinaryOperator::PGCustomBinaryOperator(idents) => {
305310
write!(f, "OPERATOR({})", display_separated(idents, "."))
306311
}
312+
BinaryOperator::Overlaps => f.write_str("OVERLAPS"),
307313
}
308314
}
309315
}

src/dialect/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ pub trait Dialect: Debug + Any {
512512
Token::Word(w) if w.keyword == Keyword::IS => Ok(p!(Is)),
513513
Token::Word(w) if w.keyword == Keyword::IN => Ok(p!(Between)),
514514
Token::Word(w) if w.keyword == Keyword::BETWEEN => Ok(p!(Between)),
515+
Token::Word(w) if w.keyword == Keyword::OVERLAPS => Ok(p!(Between)),
515516
Token::Word(w) if w.keyword == Keyword::LIKE => Ok(p!(Like)),
516517
Token::Word(w) if w.keyword == Keyword::ILIKE => Ok(p!(Like)),
517518
Token::Word(w) if w.keyword == Keyword::RLIKE => Ok(p!(Like)),

src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,7 @@ impl<'a> Parser<'a> {
30603060
Keyword::AND => Some(BinaryOperator::And),
30613061
Keyword::OR => Some(BinaryOperator::Or),
30623062
Keyword::XOR => Some(BinaryOperator::Xor),
3063+
Keyword::OVERLAPS => Some(BinaryOperator::Overlaps),
30633064
Keyword::OPERATOR if dialect_is!(dialect is PostgreSqlDialect | GenericDialect) => {
30643065
self.expect_token(&Token::LParen)?;
30653066
// there are special rules for operator names in

tests/sqlparser_common.rs

+5
Original file line numberDiff line numberDiff line change
@@ -12808,3 +12808,8 @@ fn parse_update_from_before_select() {
1280812808
parse_sql_statements(query).unwrap_err()
1280912809
);
1281012810
}
12811+
12812+
#[test]
12813+
fn parse_overlaps() {
12814+
verified_stmt("SELECT (DATE '2016-01-10', DATE '2016-02-01') OVERLAPS (DATE '2016-01-20', DATE '2016-02-10')");
12815+
}

0 commit comments

Comments
 (0)