Skip to content

[BUG] IS NOT NULL renders as IS NULL (NOT dropped on round-trip) #530

Description

@basili4-1982

Bug Description

Round-trip rendering drops the NOT qualifier: a query WHERE email IS NOT NULL
is re-emitted as WHERE email IS NULL.

Root cause

pkg/sql/parser/expressions_operators.go stores IS NOT NULL as
BinaryExpression{Operator: "IS NULL", Not: true}. BinaryExpression.SQL()
(pkg/sql/ast/sql.go) renders the operator string verbatim and ignores the
Not flag in the null branch, silently inverting the predicate.

To Reproduce

tree, _ := gosqlx.Parse("SELECT * FROM users WHERE email IS NOT NULL")
fmt.Println(tree.SQL())
// SELECT * FROM users WHERE email IS NULL  (NOT lost!)

Expected Behavior

SELECT * FROM users WHERE email IS NOT NULL

Notes

Exists in v1.14.0 and current main (31b5b1c). Affects both PostgreSQL and
ClickHouse dialects. PR: #529.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions