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
Bun.SQL with prepare:false serializes object JSONB parameters as "[object Object]" #30221
Run this with DATABASE_URL pointing to PostgreSQL:
import{SQL}from"bun";constsql=newSQL({url: process.env.DATABASE_URL!,max: 1,prepare: false,});try{constpayload={hello: "world"};const[row]=awaitsql` SELECT ${payload}::jsonb AS value `;console.log(row);}finally{awaitsql.end();}Forcomparison,bothofthesework:
// Works with prepare:false if JSON is pre-stringified:awaitsql` SELECT ${JSON.stringify({hello: "world"})}::jsonb AS value`;// Works with prepare:true using the raw object:constpreparedSql=newSQL({url: process.env.DATABASE_URL!,max: 1,prepare: true,});awaitpreparedSql` SELECT ${{hello: "world"}}::jsonb AS value`;
This matters for PgBouncer/Supavisor transaction-pooler usage, where Bun’s docs recommend prepare: false.
What is the expected behavior?
With prepare: false, binding a plain JS object into a jsonb parameter should serialize it as JSON, matching the prepare: true
behavior.
What do you see instead?
PostgreSQL receives [object Object] and rejects it as invalid JSON:
PostgresError: invalid input syntax for type json
errno: "22P02"
detail: "Token \"object\" is invalid."
where: "JSON data, line 1: [object...\nunnamed portal parameter $1 = '...'"
routine: "json_errsave_error"
code: "ERR_POSTGRES_SERVER_ERROR"
✅ Reproduced against local Postgres — writeBind fell through to String.fromJS (→ Object.prototype.toString) for object params when Parse sent OID 0 for prepare: false. Fix re-derives the tag with Tag.fromJS when the slot is unspecified and routes JSON-shaped values through jsonStringifyFast.
Duplicate of #29010. Both issues report the same problem: Bun.SQL (Postgres) with prepare: false sends a Date or a plain object parameter through a generic toString(), so the server rejects the timestamp or json value, while the same query works with prepare: true. Closing this one to keep the discussion in one place. Please follow #29010. If you think this is a different problem, comment here and it can be reopened.
Activity
robobun commentedon May 4, 2026
✅ Reproduced against local Postgres —
writeBindfell through toString.fromJS(→Object.prototype.toString) for object params when Parse sent OID 0 forprepare: false. Fix re-derives the tag withTag.fromJSwhen the slot is unspecified and routes JSON-shaped values throughjsonStringifyFast.Fix in #30222.
test: docker-free mock backend for #30221 wire-protocol assertions
sql: JSON-stringify object parameters when Parse uses inferred OIDs
test: docker-free mock backend for #30221 wire-protocol assertions
CoffeeFlux commentedon Jun 16, 2026
This one's burning us too; we're still on 1.3.10 due to it.
Aokoooooo commentedon Jun 24, 2026
any updates?
robobun commentedon Sep 13, 2026
Duplicate of #29010. Both issues report the same problem:
Bun.SQL(Postgres) withprepare: falsesends a Date or a plain object parameter through a generictoString(), so the server rejects the timestamp or json value, while the same query works withprepare: true. Closing this one to keep the discussion in one place. Please follow #29010. If you think this is a different problem, comment here and it can be reopened.Dateparameters via.toString()instead of.toISOString()forprepare:false#29010sql: consolidate the open Bun.sql, bun:sqlite and node:sqlite pull re…