Repository navigation
Conversation
Adds parsing for the SQL standard BETWEEN SYMMETRIC / ASYMMETRIC modifiers, e.g. `a NOT BETWEEN SYMMETRIC 10 AND 1`. See https://www.postgresql.org/docs/current/functions-comparison.html
…mmetric # Conflicts: # tests/sqlparser_common.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2522 +/- ##
=======================================
Coverage 80.96% 80.96%
=======================================
Files 42 42
Lines 33359 33364 +5
Branches 33359 33364 +5
=======================================
+ Hits 27009 27014 +5
Misses 2790 2790
Partials 3560 3560 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LucaCappelletti94
left a comment
There was a problem hiding this comment.
You should add the Dialect trait method the parser suggestion calls:
fn supports_in_empty_list(&self) -> bool {
false
}
+
+ /// Returns true if the dialect supports `BETWEEN [ ASYMMETRIC | SYMMETRIC ]`.
+ fn supports_between_symmetric(&self) -> bool {
+ false
+ }Then, you should enable it for PostgreSQL and the generic dialect, where both keywords are reserved.
fn supports_comment_optimizer_hint(&self) -> bool {
true
}
+
+ fn supports_between_symmetric(&self) -> bool {
+ true
+ }
}| let symmetric = if self.parse_keyword(Keyword::SYMMETRIC) { | ||
| true | ||
| } else { | ||
| let _ = self.parse_keyword(Keyword::ASYMMETRIC); | ||
| false | ||
| }; |
There was a problem hiding this comment.
You should gate the modifier behind a dialect method. Consumed unconditionally, it breaks a BETWEEN symmetric AND 5 in every dialect where symmetric is an ordinary identifier.
| let symmetric = if self.parse_keyword(Keyword::SYMMETRIC) { | |
| true | |
| } else { | |
| let _ = self.parse_keyword(Keyword::ASYMMETRIC); | |
| false | |
| }; | |
| let symmetric = self.dialect.supports_between_symmetric() | |
| && self.parse_one_of_keywords(&[Keyword::SYMMETRIC, Keyword::ASYMMETRIC]) | |
| == Some(Keyword::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", | ||
| ); |
There was a problem hiding this comment.
Some additional red tests.
| // 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", | |
| ); | |
| // See https://www.postgresql.org/docs/current/functions-comparison.html | |
| let supported = all_dialects_where(|d| d.supports_between_symmetric()); | |
| match supported.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. | |
| supported.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", | |
| ); | |
| let unsupported = all_dialects_where(|d| !d.supports_between_symmetric()); | |
| unsupported.verified_expr("a BETWEEN symmetric AND 5"); | |
| unsupported.verified_expr("a BETWEEN asymmetric AND 5"); |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Before this fix, PostgreSQL's
BETWEEN SYMMETRIC/BETWEEN ASYMMETRICmodifier wasn't parsed:This adds a
symmetricfield toExpr::Betweenand parses the optionalSYMMETRIC/ASYMMETRICkeyword afterBETWEEN(per the SQL standard / PostgreSQL docs: https://www.postgresql.org/docs/current/functions-comparison.html).ASYMMETRICis the default behavior and is not round-tripped in the displayed SQL.AI assistance disclosure: this change was drafted with GitHub Copilot.