Skip to content

[BUG] JSQLParser 5.4-SNAPSHOT : PostgreSQL : jsonb operator "?" fails together with JDBC named parameters (regression via #2466) #2475

Description

@fudianchn

Failing SQL Feature:

Using the PostgreSQL jsonb existence operator ? in a condition that also contains a JDBC named parameter (:name).

The ternary lookahead introduced with the ClickHouse ternary support (#2466) treats any standalone : at bracket depth 0 as the ternary else separator. A JDBC named parameter starts with exactly the same : token, so the parser commits to the ternary reading of the ? and then fails waiting for its closing :.

SQL Example:

SELECT * FROM t WHERE j ? :key
SELECT * FROM t WHERE j ? 'k' AND x = :p

Both throw a JSQLParserException on current master, although SELECT * FROM t WHERE j ? 'k' (no named parameter) and SELECT * FROM t WHERE x = :p (no ?) each parse fine. Both statements parsed fine on the commit right before #2466 (verified on 2989cb1: j ? :key parses as a JsonOperator with a named parameter operand), so this is a regression introduced by #2466.

Verified on master 7b64825.

The ternary else separator can only follow a token which can END an expression (identifier, literal, JDBC parameter, balanced closing bracket), because the then-branch must be a complete expression. A : in operand position (directly after an operator such as =, AND, or directly after the leading ?) starts a named parameter instead and must not close the then-branch.

Software Information:

  • JSqlParser version: 5.4-SNAPSHOT (master 7b64825)
  • Database: PostgreSQL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions