Skip to content

A non-boolean value sent to a boolean column is stored as false #42

Open

Description

@okomarov

The boolean serializer in src/types.js is x => x === true ? 't' : 'f'. When the server reports a parameter as boolean, anything other than the JavaScript value true is sent as f:

await sql`insert into t (flag) values (${1})`      // stored false
await sql`insert into t (flag) values (${'true'})` // stored false
await sql`insert into t (flag) values (${'t'})`    // stored false

PostgreSQL itself reads 1, 'true', 't', 'yes' and 'on' as true, and rejects input it can't read. Here nothing fails and the opposite value is stored. Strings like 'true' arrive this way from forms, query strings and CSV imports.

Upstream treats this as intended: porsager#858 asked about 't' and was closed with a pointer to the serializer. The README doesn't mention it.

Options:

  • Send anything that isn't a JS boolean as text, so PostgreSQL applies its own boolean input rules and rejects invalid input.
  • Or throw for non-boolean values.

Either changes what is stored for code that relies on today's behaviour, so it belongs in a major version or behind the parameter-encoding change discussed in #41.

Activity

  1. added
    bug
    on Oct 13, 2026
  2. moved this to In progress in Roadmapon Oct 15, 2026
  3. okomarov commented on Oct 15, 2026

    @okomarov
    Author

    Available in 4.5.0-rc1 with parameter_types: 'client' (npm install @steadybrew/postgresjs@next). parameter_types: 'warn' reports which of your queries 'client' would send differently; see Parameter types. This stays open until 'client' becomes the default in 5.0.

  4. added
    area: serialization
    upstream
    on Oct 16, 2026
  5. moved this from In progress to Later in Roadmapon Oct 24, 2026
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

    area: serializationbugupstream

    Type

    No type

    Projects

    • Status
      Later

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions