BenSatori commented on code in PR #2522:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2522#discussion_r4766925273
##########
src/parser/mod.rs:
##########
@@ -4457,8 +4457,14 @@ impl<'a> Parser<'a> {
Ok(in_op)
}
- /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was
already consumed.
+ /// Parses `[ASYMMETRIC | SYMMETRIC] <low> AND <high>`, assuming the
`BETWEEN` keyword was already consumed.
pub fn parse_between(&mut self, expr: Expr, negated: bool) -> Result<Expr,
ParserError> {
+ let symmetric = if self.parse_keyword(Keyword::SYMMETRIC) {
+ true
+ } else {
+ let _ = self.parse_keyword(Keyword::ASYMMETRIC);
+ false
+ };
Review Comment:
Done in 0bb434c7: added `supports_between_symmetric()` (next to
`supports_in_empty_list`), enabled it for PostgreSQL and Generic, and applied
the suggestion as-is.
##########
tests/sqlparser_common.rs:
##########
@@ -20067,6 +20071,26 @@ fn parse_insert_by_name() {
}
}
+#[test]
+fn parse_between_symmetric() {
+ // See https://www.postgresql.org/docs/current/functions-comparison.html
+ match verified_expr("1 BETWEEN SYMMETRIC 2 AND 3") {
+ Expr::Between {
+ symmetric, negated, ..
+ } => {
+ assert!(symmetric);
+ assert!(!negated);
+ }
+ _ => unreachable!(),
+ }
+
+ // ASYMMETRIC is the default behavior and is not preserved as SQL text.
+ one_statement_parses_to(
+ "SELECT * FROM t WHERE 1 NOT BETWEEN ASYMMETRIC 2 AND 3",
+ "SELECT * FROM t WHERE 1 NOT BETWEEN 2 AND 3",
+ );
Review Comment:
Added as suggested; it fails without the gating and passes with it. I also
added the converse typed-error case: where supported, `a BETWEEN symmetric AND
5` is rejected since `SYMMETRIC` is reserved there. Also merged main, which
needed `symmetric: false` on two new `Expr::Between` literals in
`sqlparser_sqlite.rs`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]