porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.26k stars 262 forks source link

[dblink] str.replace is not a function #712

Closed marxangels closed 10 months ago

marxangels commented 10 months ago
await sql`SELECT dblink(
    'host=127.0.0.1 dbname=dbname user=username password=secret port=5432 sslmode=require',
    'INSERT INTO sys_orders ${sql(orders, ...Object.keys(orders[0]))} ON CONFLICT DO NOTHING'
)`
TypeError: str.replace is not a function
    at escape (file:///app/node_modules/postgres/src/types.js:214:20)
    at file:///app/node_modules/postgres/src/types.js:210:22
    at Array.map (<anonymous>)
porsager commented 10 months ago

If I'm reading your query right, you're trying to generate sql to put into a string that contains sql to the dblink function.

Dynamic parameters can't be used inside a string value.