Skip to content

Params for nullable columns accept null, which can never match #299

Description

@tiagolauer

Params for nullable columns accept null, even though = NULL never matches a row in SQL:

// schema: email: string | null
Params<DB, 'select id from users where email = $1'>  // [string | null]
db.query('select id from users where email = $1', null); // compiles, matches nothing

Join-induced nullability leaks the same way:

Params<DB, 'select u.id from users u left join posts p on u.id = p.user_id where p.views = $1'>
// [number | null]

The LEFT JOIN case shows the mechanism plainly: the | null belongs to the result side (a missing match makes the column null in the output), not to the value you compare against. like $1 behaves the same.

Root cause: ParamType resolves through ResolveColumnLoose (src/params.ts:213-223), which reuses result-column resolution verbatim, | null included. Stripping null from comparison-position params would turn the silent no-match query into a compile error, which is the kind of mistake the library is built to catch.

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