Skip to content

SQL builder: an operation on a nullable column declares a non-null result #31006

Open

Description

@wmadden-electric

An operation that accepts a nullable column declares a non-null result, so a selected result can be null while its type says it can't:

const rows = await runtime().query(
  db()
    .public.users.outerLeftJoin(db().public.profiles, (f, fns) => fns.eq(f.users.id, f.profiles.user_id))
    .select('bioMatches', (f, fns) => fns.ilike(f.profiles.bio, '%BIO%'))
    .build(),
);
// bioMatches is typed boolean, but Postgres returns null for a user with no profile

In a where this does no harm, because a NULL condition excludes the row. It matters only when the result is selected.

Every operation that takes a nullable receiver has this gap:

  • pgvector: cosineDistance and the other distance operations (packages/3-extensions/pgvector/src/types/operation-types.ts).
  • PostGIS: distance and the other measurement operations (packages/3-extensions/postgis/src/types/operation-types.ts).
  • Postgres target: ilike and fullTextMatches (packages/3-targets/postgres/1-target/src/types/operation-types.ts).

What we want

The result's nullability follows the receiver's: a nullable column gives a nullable result, and a non-null column keeps the non-null result it has today. The static result types and the run-time returns.nullable descriptors both need to change, across every extension at once, so the SQL builder stays consistent.

Activity

  1. sundeep8967 commented on Nov 13, 2026

    @sundeep8967

    Hi team, I would like to help resolve this issue. I have reproduced the typing and run-time mismatch where operations on nullable receiver columns declare non-null results in selected projections across the SQL builder extension operation types (, , and targets). Could you please assign this to me?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions