Parser: fix IS [NOT] DISTINCT FROM right-operand precedence - #2443
Closed
MohamedAbdeen-rs wants to merge 1 commit into
Closed
Parser: fix IS [NOT] DISTINCT FROM right-operand precedence#2443MohamedAbdeen-rs wants to merge 1 commit into
MohamedAbdeen-rs wants to merge 1 commit into
Conversation
`IS DISTINCT FROM` and `IS NOT DISTINCT FROM` parsed their right operand with parse_expr, which starts at the lowest precedence and therefore absorbed every operator that followed, including AND and OR. So `a IS DISTINCT FROM b AND c` parsed as `a IS DISTINCT FROM (b AND c)` instead of `(a IS DISTINCT FROM b) AND c`, accepting a boolean operand where PostgreSQL takes the comparison as complete. PostgreSQL places IS below the comparison operators and above NOT, AND and OR. `Precedence::Is` already encodes exactly that, and the operator is dispatched with it; only the right operand ignored it. Every other infix operator in parse_infix parses its right operand with parse_subexpr(precedence), so do the same for these two. Operators binding tighter than IS still join the right operand, so `a IS DISTINCT FROM b + c` and `a IS DISTINCT FROM b = c` are unchanged, and a parenthesized conjunction still reaches it. Adds precedence tests for both spellings against AND, OR, NOT, `+`, `=`, parentheses, and a WHERE clause conjoining two of these comparisons.
This was referenced Aug 19, 2026
Contributor
|
Seems like a duplicate of #2436, could you please check and determine whether this PR should be closed in favour of the pre-existing one? |
I looked at both and I think #2436 is more complete. I suggest we close this PR. Thanks for your contribution @MohamedAbdeen-rs |
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.
IS DISTINCT FROMandIS NOT DISTINCT FROMparsed their right operand with parse_expr, which starts at the lowest precedence and therefore absorbed every operator that followed, including AND and OR. Soa IS DISTINCT FROM b AND cparsed asa IS DISTINCT FROM (b AND c)instead of(a IS DISTINCT FROM b) AND c.PostgreSQL places IS below the comparison operators and above NOT, AND and OR.
Precedence::Isalready encodes exactly that.