Repository navigation
PostgreSQL: Fix unary +/- precedence before exponentiation - #2829
Surajsuthar wants to merge 10 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2829 +/- ##
=======================================
Coverage 83.20% 83.20%
=======================================
Files 42 42
Lines 36471 36472 +1
Branches 36471 36472 +1
=======================================
+ Hits 30345 30346 +1
Misses 2632 2632
Partials 3494 3494 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LucaCappelletti94
left a comment
There was a problem hiding this comment.
SQLiteDialect::prec_value matches every variant, so it needs the new one too.
- Precedence::MulDivModOp => 40,
+ Precedence::MulDivModOp | Precedence::UnaryPlusMinus => 40,I have looked into whether this precedence bug applies also to the other dialects, and it does in some, so it will need to be addressed. DuckDB, MySQL and MariaDB all bind ^ tighter than * (2 * 3 ^ 2 is 18 in DuckDB 1.4.4, and 2 * 3 ^ 1 is 4 in MySQL 8.4 and MariaDB 11.8), while the DuckDB and MySQL dialects parse (2 * 3) ^ n. The DuckDB dialect also parses ^ as BitwiseXor, although it is exponentiation there. Those fixes are outside this PR and can follow separately once the new level lands, since their tables need UnaryPlusMinus above Caret. If you happen to have time, such PRs would be welcomed.
LucaCappelletti94
left a comment
There was a problem hiding this comment.
In a little while I will open a PR adding a fuzzer exactly aimed at finding these issues, do use it before the next review round as I think it could be useful. It unfortunately finds still several expression priority issues.
There was a problem hiding this comment.
You could rename this seed to postgres_2829_unary_minus_caret.sql, since every other fuzz_seeds/<dialect>_<n>_*.sql name carries the number of the sqlparser PR that added it, and 27094 is the DataFusion issue.
Add dialect-specific precedence for unary
+and-so PostgreSQLbinds them more tightly than
^, while preserving generic-dialect behavior.#2819