Operator precedence is inconsistent with modern PG (and PG 7.2)
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
DataFusion's current operator precedence is (high to low):
```
- 45: * / %
- 40: + -
- 30: IS DISTINCT FROM, IS NOT DISTINCT FROM, regex (~, !~, ~*, !~*), bitwise, ||, …
- 25: LIKE / NOT LIKE / ILIKE / NOT ILIKE
- 20: < >
- 15: = != <= >=
- 10: AND
- 5: OR
```
[Modern Postgres ](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE)implements:
```
- * / %
- + -
- (any other operator: ||, regex, bitwise)
- BETWEEN IN LIKE ILIKE SIMILAR (non-assoc)
- < > = <= >= <> (non-assoc, all six together)
- IS ISNULL NOTNULL (incl. IS DISTINCT FROM)
- NOT, AND, OR
```
We claim to match Postgres 7.2, which does:
```
- IS, ISNULL, NOTNULL (rank 6 — high)
- (any other operator — ||, regex, bitwise, and <=, >=, <> since they aren't listed) (rank 7)
- LIKE ILIKE (rank 11)
- < > (rank 12)
- = (rank 13)
```
So we're consistent with neither version of Postgres. I'd argue we should move to be consistent with modern Postgres.
### Describe the solution you'd like
_No response_
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.