Skip to content

[BUG]: Operator precedence of = and IS NULL is disrespected when using eq and isNull #4878

@akoll

Description

@akoll

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.44.4

What version of drizzle-kit are you using?

0.31.4

Other packages

No response

Describe the Bug

When using Drizzle's operator wrappers eq and isNull (or isNotNull), no parantheses are generated to explicitly declare an evaluation precedence.

The call to

eq(foo, isNull(bar))

evaluates to

foo = bar is null

which is incorrect when targeting Postgres >= 9.5.
The operator precedence given in the PostgreSQL documentation ranks equality (=) above IS NULL so parantheses would be necessary here:

foo = (bar is null)

As a result, the expressions eq(foo, isNull(bar)) and isNull(eq(foo, bar)) are currently equivalent as they both evaluate to foo = bar is null.

I assume that at least the current MySQL and SQLite versions are also affected, where these operators have the same precedence (which means the bug only appears half of the time, depending on the written order).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions