-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interval multiplication parses differently depending on operand order #1345
Comments
I looked into this, since I think that's the root cause of apache/datafusion#12190 (Thanks @tshauck for the pointer). I think changing These PR might be relevant:
I think this syntax is used for the MySQL/BigQuery dialects. |
Wow MySQL is I guess it would need a separate flag in dialect then, something like "suports expressions in interval values", as PostgreSQL does not seem to support that. |
I think that makes sense. I think a somewhat similar alternative is to define how binary operators between intervals are parsed. As an example: Following is how you binop intervals in postgresql/Datafusion: select interval '1' day + interval '2' day --allowed
select interval '1 + 2' day --not allowed Following is how you binop intervals in mysql select interval 1 + 1 day --allowed
select interval 1 day + interval 1 day --not allowed There might be other approaches/syntax for binary operations between intervals. Not sure |
I take it back. I think postgres does kinda support that, just not in the same way select interval '1 month + 2 day' day However, it shouldn't matter actually for sqlparser, since it will just be |
Following PR that has been recently merged might be relevant: |
cc @alamb |
@samuelcolvin has also made some good progress on cleaning up interval parsing recently. Perhaps you can retry the example with the recently release sqlparser 0.51.0 |
Yes, I've rechecked, and my examples parses fine on |
Depending on operands order, intervals without leading fields (with literal alone) parses differently.
I've checked on
sqlparser = "0.48.0"
SELECT 1 * interval '1 month';
parses asBinOp(Number, Interval(String))
, which, I think, is correct:But
SELECT interval '1 month' * 1;
parses asInterval(BinOp(String, Number))
, which, to me, is incorrect:I think that culprit is these calls
https://github.com/sqlparser-rs/sqlparser-rs/blob/20f7ac59e38d52e293476b7ad844e7f744a16c43/src/parser/mod.rs#L2027
=>
https://github.com/sqlparser-rs/sqlparser-rs/blob/20f7ac59e38d52e293476b7ad844e7f744a16c43/src/parser/mod.rs#L906
It would consume not only literals, but any expression as well, and store result as Intervals
value
I propose to change
parse_interval_expr
so it would allow only literals, or maybe even replace it withparse_value
.I didn't actually check if that would break any tests, but at first glance it should not.
Also representation of interval value in AST could be changed from
Expr
toValue
, but that would break public API, so could be postponed.Related:
#517
#705
The text was updated successfully, but these errors were encountered: