Repository navigation
Let postfix IS tests chain onto predicate results - #2840
Merged
manticore-projects merged 1 commit intoOct 21, 2026
Merged
Conversation
A boolean test applied to a comparison or another predicate was a
parse error: a > 0 IS TRUE, a IN (1, 2) IS FALSE, a IS NULL IS NOT
TRUE all failed at the IS, though SQL:2016 6.39 applies IS [NOT]
{TRUE|FALSE|UNKNOWN} to any boolean primary and PostgreSQL, MySQL
and SQLite accept the forms.
After the first condition suffix, postfix IS predicates (IS [NOT]
NULL / TRUE / FALSE / UNKNOWN / JSON) now chain onto the result. A
semantic guard keeps the loop from claiming IS DISTINCT FROM and
from consuming a column's NOT NULL constraint after a DEFAULT
expression.
Fixes JSQLParser#2759
Contributor
That's a strong argument, even I can't ignore. |
| | LOOKAHEAD(3) result=IsDistinctExpression(left) | ||
| | result=SimilarToExpression(left) | ||
| ) | ||
| // SQL:2016 6.39: a boolean test applies to any boolean primary, |
Contributor
There was a problem hiding this comment.
Kudos, clean documentation! I like this.
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.
Summary
A boolean test applied to a comparison or another predicate is a parse error:
a > 0 IS TRUE,a IN (1, 2) IS FALSEanda IS NULL IS NOT TRUEall fail at theIS, while the same tests on a bare column or a parenthesized comparison parse (#2759).SQL:2016 6.39 defines
<boolean test> ::= <boolean primary> [ IS [NOT] <truth value> ], so the test applies to any boolean primary. PostgreSQL, MySQL and SQLite all accept these forms.The condition suffix dispatch fired once:
a > 0consumed the>comparison and the trailingIS TRUEhad nowhere to go. Postfix IS predicates (IS [NOT] NULL / TRUE / FALSE / UNKNOWN / JSON) now chain onto the result of any earlier suffix in a loop.Two traps the loop has to avoid, both covered by a semantic guard (
isPostfixIsTestAhead) rather than first tokens:IS DISTINCT FROMis also IS-led but takes a right-hand operand; the guard only enters on TRUE/FALSE/UNKNOWN/NULL/JSON, soa IS DISTINCT FROM bstill resolves through the existing first-suffix dispatch.NOT NULLas a column constraint after a DEFAULT expression (CREATE TABLE t (a INT DEFAULT 1 > 0 NOT NULL, ...)) is inIsNullExpression's first set; the guard rejects it before the loop commits, so that path is unchanged.Test plan
SELECT * FROM t WHERE a > 0 IS TRUEparses and round-tripsSELECT * FROM t WHERE a IN (1, 2) IS FALSEparses and round-tripsSELECT * FROM t WHERE a IS NULL IS NOT TRUEchains both testsSELECT * FROM t WHERE a IS TRUE IS FALSEchains a test onto a testCREATE TABLE t (a INT DEFAULT 1 > 0 NOT NULL, b INT)keepsNOT NULLas a column constraint (existingColumnDefaultExpressionTest)