Skip to content

Null safe equality inconsistency #4289

@CertainLach

Description

@CertainLach

What happened?

PRQL is not consistent with null comparisons, it transforms == null and != null to IS NULL and IS NOT NULL, yet does not emit similar things for two column comparisons.

Given that == is already null safe in some contexts, it should also be null-safe in others, I.e using

PRQL input

prql target:sql.postgres
from test
derive {
  a == "a",
  a == b,
  a == null && b == null
}

SQL output

SELECT
  *,
  a = 'a', -- Ok: nothing wrong will happen if a is NULL
  a = b, -- Error: Wrong result if a and b is NULL
  a IS NULL
  AND b IS NULL
FROM
  test

Expected SQL output

SELECT
  *,
  a = 'a',
  a IS NOT DISTINCT FROM b, -- Ok: We don't know if a or b might be NULL, so we need to be strict here
  a IS NULL
  AND b IS NULL
FROM
  test

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions