compiler-segfault opened a new pull request, #2830:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2830

   `SELECT -1 ^ 0` is parsed as `-(1 ^ 0)` by `PostgreSqlDialect`, so it yields 
`-1` where PostgreSQL yields `1`; `SELECT +2 ^ 2` yields `-4` instead of `4`.
   
   ```text
   PostgreSQL 17:  SELECT -1 ^ 0;  ->  1
   sqlparser:      UnaryOp { op: Minus, expr: BinaryOp { .., op: PGExp, .. } }
   ```
   
   In gram.y `UMINUS` is declared above `COLLATE`, `AT` and `^`, so the operand 
of a unary `+`/`-` may only take `.`, `::` and `[]`. The operand precedence is 
now a `Dialect` method that defaults to the previous `MulDivModOp` value, and 
`PostgreSqlDialect` returns the `COLLATE` level. That also makes `-a AT TIME 
ZONE 'tz'` parse as `(-a) AT TIME ZONE 'tz'`, which is the same reading gram.y 
gives.
   
   [PostgreSQL precedence 
table](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE)
   
   `parse_unary_operand_binds_tighter_than_exponentiation` is added to 
`tests/sqlparser_postgres.rs`; without the change it fails with the AST quoted 
above.
   
   `cargo test --all-features`, `cargo fmt --all` and `cargo clippy 
--all-targets --all-features -- -D warnings` all pass.
   
   Prepared with AI assistance; I reviewed the diff and ran the checks above.
   
   Fixes #2819.
   


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