Skip to content

Custom binary parameters work individually but fail inside bytea arrays #3872

Backlog

Description

@FFspiky

With pg 8.23.1 at 2a5850fb0db18f5e40a642bbb4a4743de412ab54, a custom value returning a Buffer from toPostgres() works as a scalar parameter but throws inside an array:

const value = { toPostgres: () => Buffer.from([0, 128, 255]) }
await client.query('SELECT $1::bytea AS value', [value]) // works
await client.query('SELECT $1::bytea[] AS value', [[value]])
// TypeError: elementRepresentation.replace is not a function

The same applies when the hook returns a typed-array view or DataView. Array elements are documented to follow the same recursive conversion rules. The array fallback currently passes the prepared Buffer to string escaping instead of its existing binary encoder.

Observed on macOS, Node v25.9.0, PostgreSQL 18.1. This concerns existing Buffer/view conversion; it is separate from nullish hook results (#3845), new ArrayBuffer support (#3857), and named-statement recovery after a serialization error (#3867).

Investigated and verified with OpenAI Codex under the account owner's authorization.

Environment: Node 25.9.0, PostgreSQL 18.1, macOS arm64. Codex reproduced this with a local PostgreSQL instance and prepared this report.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions