Skip to content

Precedence of NOT isn't quite right #81

@benesch

Description

@benesch

It took me a while to come up with this example, and it's not totally realistic, but it's probably still worth fixing. Basically, the precedence of NOT LIKE is mishandled, because the precedence of NOT is fixed to its unary operator precedence, when in it needs to vary based on whether the NOT keyword is followed by LIKE/BETWEEN/IN/.

Concretely, SELECT a LIKE b IS NULL parses correctly, with the LIKE binding more tightly than the IS NULL:

SQLIsNull(
    SQLBinaryExpr {
        left: SQLIdentifier(
            "a"
        ),
        op: Like,
        right: SQLIdentifier(
            "b"
        )
    }
)

But when NOT LIKE is substituted for LIKE, the IS NULL incorrectly binds more tightly than the NOT LIKE:

SQLBinaryExpr {
    left: SQLIdentifier(
        "a"
    ),
    op: NotLike,
    right: SQLIsNull(
        SQLIdentifier(
            "b"
        )
    )
}

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