Skip to content

IS_NOT_NULL() does not always add enough parentheses to the compiled SQL #500

Open
@kblomster

Description

@kblomster

Describe the bug
Consider this Jet statement:

postgres.SELECT(postgres.Bool(true).EQ(postgres.String("foo").IS_NOT_NULL()))

It compiles to

SELECT TRUE::boolean = 'foo'::text IS NOT NULL;

Which, when you run it in Postgres, results in this error:

[42883] ERROR: operator does not exist: boolean = text
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Position: 22

We get the error because the = operator has higher precedence than IS [NOT] NULL, so the expression gets parsed like this:

SELECT (TRUE::boolean = 'foo'::text) IS NOT NULL;

Environment (please complete the following information):

  • OS: macosx
  • Database: postgres 14
  • Database driver: pgx
  • Jet version: 2.13.0

Expected behavior
Jet knew what we meant. The .EQ() method was expecting a BoolExpression and we gave it a BoolExpression, so I would have expected the query compiler to put parens around that expression:

SELECT TRUE::boolean = ('foo'::text IS NOT NULL);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions