LucaCappelletti94 opened a new pull request, #2665:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2665

   Follow-up to #2664, which this PR is stacked on.
   
   PostgreSQL, DuckDB and Spark accept one comparison in the lower bound of a 
`BETWEEN`, as in `x BETWEEN 1 > 0 AND y`, but reject `IS`, `LIKE` or a nested 
`BETWEEN` there. PostgreSQL 16 and DuckDB 1.4.4 run `SELECT true BETWEEN 1 > 0 
AND true`, `true BETWEEN 1 <> 2 AND true` and `true BETWEEN 1 + 1 >= 2 AND 
true`, and both reject `true BETWEEN 1 = 1 = true AND true` with a syntax 
error. Spark's grammar parses the bound as a `valueExpression`, which includes 
`comparison` 
(https://github.com/apache/spark/blob/master/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4).
 These dialects stopped the bound before the comparison and failed with 
`Expected: AND, found: >`.
   
   A single precedence threshold cannot express this, because PostgreSQL ranks 
`LIKE` and `BETWEEN` above comparisons. A new dialect method, 
`supports_comparison_in_between_low_bound`, lets the parser read one comparison 
after the bound, with its right side parsed at `BETWEEN` precedence. It is 
enabled for PostgreSQL, DuckDB, Spark, Databricks and the generic dialect. 
Tests check the parsed bound and the rejected forms in those dialects, and the 
unchanged error everywhere else.


-- 
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]

Reply via email to