Repository navigation
PostgreSQL: bind unary plus and minus tighter than ^ - #2830
Open
compiler-segfault wants to merge 1 commit into
Open
compiler-segfault wants to merge 1 commit into
compiler-segfault wants to merge 1 commit into
Conversation
`UMINUS` is declared above `COLLATE`, `AT` and `^` in gram.y, so the operand of a unary `+`/`-` may only take `.`, `::` and `[]`. Parse it at a dialect-provided precedence instead of a hard-coded `MulDivModOp`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SELECT -1 ^ 0is parsed as-(1 ^ 0)byPostgreSqlDialect, so it yields-1where PostgreSQL yields1;SELECT +2 ^ 2yields-4instead of4.In gram.y
UMINUSis declared aboveCOLLATE,ATand^, so the operand of a unary+/-may only take.,::and[]. The operand precedence is now aDialectmethod that defaults to the previousMulDivModOpvalue, andPostgreSqlDialectreturns theCOLLATElevel. 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
parse_unary_operand_binds_tighter_than_exponentiationis added totests/sqlparser_postgres.rs; without the change it fails with the AST quoted above.cargo test --all-features,cargo fmt --allandcargo clippy --all-targets --all-features -- -D warningsall pass.Prepared with AI assistance; I reviewed the diff and ran the checks above.
Fixes #2819.