Struggling to work with JSONB `where`

So I have a jsonb column in Postgres (Using the Neon HTTP driver), and I'm trying to run a query to filter out based on the jsonb column:
await db()
.select({ id: sites.id })
.from(sites)
.where(sql`metadata @> '{"key":"${key}"}'::jsonb`)
.then(takeFirst);
await db()
.select({ id: sites.id })
.from(sites)
.where(sql`metadata @> '{"key":"${key}"}'::jsonb`)
.then(takeFirst);
Neon keeps coming back with the following error:
NeonDbError: bind message supplies 1 parameters, but prepared statement "" requires 0
NeonDbError: bind message supplies 1 parameters, but prepared statement "" requires 0
1 Reply
devlsh
devlshOP10mo ago
I checked and the query does work in raw SQL, so is there something funky perhaps going on with sql prepared statements? Seems to work if I use sql.raw() instead 🤷‍♀️
Want results from more Discord servers?
Add your server