You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A JSON string sent to a json/jsonb column is stored as a JSON string, not the value it encodes #43
The json serializer in src/types.js is x => JSON.stringify(x), applied whenever the server reports a parameter as json or jsonb. A string is therefore encoded again:
awaitsql`insert into t (doc) values (${'{"a":1}'})`// stored: "{\"a\":1}" (a JSON string), not {"a": 1}
ORMs hit this constantly because they serialize JSON columns themselves before handing values to the driver. porsager#1139 (open) reports it with Drizzle's postgres-js driver, where db.insert(t).values({ data: { foo: 'bar' } }) stores a string. The workaround is a custom json serializer that passes strings through.
Storing a JSON string is sometimes what a caller wants, so neither behaviour is right for everyone. Options:
Pass strings through unchanged, so an already-serialized value is stored as the value it encodes. Callers who want a JSON string pass JSON.stringify(s) or use sql.json(s).
Keep the default and document the custom serializer for ORM users.
The first changes what is stored, so it belongs in a major version or behind the parameter-encoding change discussed in #41. It matters for adoption: Drizzle is the most common way Postgres.js is used.
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.
Activity
feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: serialize values from their JavaScript type with parameter_type…
okomarov commentedon Oct 15, 2026
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.