Skip to content

Boolean created by comparing two not null timestamps is incorrectly nullable. #199

Open
@kfajdsl

Description

@kfajdsl

Describe the bug
When comparing two not null timestamps, the result will never be null, but SafeQL interprets it at nullable.

To Reproduce
Steps to reproduce the behavior:
Create a table with a NOT NULL timestampz column:

CREATE TABLE token (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  expires_at TIMESTAMPZ NOT NULL DEFAULT NOW()
);

Query that table, checking if the timestamp is in the past:

  const tokenExpired = (await sql<{ expired: boolean; }[]>`
    SELECT expires_at < NOW() AS expired
    FROM token
    WHERE id = ${tokenId}
  `)[0]?.expired;

SafeQL now reports an error,

Query has incorrect type annotation.
	Expected: { expired: boolean; }
	Actual: { expired: boolean | null; }[]

Expected behavior
SafeQL doesn't report an error.

Desktop (please complete the following information):

  • OS: macOS
  • PostgreSQL version: 16.1

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