-
Notifications
You must be signed in to change notification settings - Fork 605
Outdated operation precedence. #814
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
Comments
@michael-2956, you're right, this has been a problem for a while. Not sure if we have an issue with that, but that is known. I don't have the time to search about it and implement it, since the precedence may vary from each database, and it's quite a complex part of the code. But I'd love to review it if you feel like doing a PR for it! |
@AugustoFKL, Is it ok to change lots of code in |
@michael-2956 I prefer to add permissiveness over break backward compatibility. If the precedence can't be generic for all dialects, I think it's better to specialize it. Of course, this isn't something simple at all, but I don't like the idea of breaking what we have right now. |
@AugustoFKL So, putting it into a dialect was a right decision after all? There is a lot of redundancy in the dialect code on my fork, but I've tested it and I think it works fine (at least in my use cases). And, in summary, I did have to change some parsing code to fix precedence issues, but mostly I just changed the numbers. I think that those non-numbers issues I've come to fix were not exclusive to Postgres, so maybe I should move those fixes to parser.rs, and, possibly through some kind of a get_precedence() function, make it possible for the dialect to have its own precedence. Would that be ok? Unfortunately, modifying get_next_precedence turned out to be not enough for me. That's because the 'numbers' are not only used in the function but all over the parsing code. |
@michael-2956, that would be ok... I'll take a look at your code this week, but, if the changes don't cause significant API changes or break backward compatibility, I don't see the problem. |
I'm not sure if this is the same issue, but currently use sqlparser::dialect::PostgreSqlDialect;
use sqlparser::parser::Parser;
fn main() {
let sql = r#"SELECT 'foo'->'bar'='spam'"#;
let dialect = PostgreSqlDialect {};
let ast = Parser::parse_sql(&dialect, sql).unwrap();
dbg!(ast);
} Contains:
|
Here's an expression:
SELECT ~1 + 2
. If you plug it intoPostgreSQL
interpreter, here's what the output looks like:As you can see here, and according to operation precedence listed in documentation, the
+
operation is more powerful than the~
operation, and thus we have PGBitwiseNot(1 + 2). However, if we plug this into the parser, we get the following AST:Which is implying
(~1) + 2
instead of~(1 + 2)
. This should be fixed.UPDATE:
In code, I found a reference to an old PostgreSQL precedence table, using which the parser is built. However, this table is for a very old (
7.0
, releasedMay 8, 2000
) version of PostgreSQL. There latest version is15.1
. Shouldn't this be updated?The text was updated successfully, but these errors were encountered: