Skip to content
Advertisement

Postgres + Node – Parameter Query with $1, $2, $3 giving error

I’m getting this nodejs error when I try running my query with params ($1, $2, $3). The query works in postgres. It also works if I don’t use the params ($1, $2, $3) and instead substitute values in for them. Could someone help me identify the issue?

The query I’m trying to run:

Advertisement

Answer

Postgresql does not support parameters to an anonymous block

The relevant doc https://www.postgresql.org/docs/9.4/sql-do.html

Relevant ticket https://github.com/brianc/node-postgres/issues/812

Migrating into using a stored procedure or function appears to be your best way to proceed. The ticket has an suggestion using CREATE TEMPORARY FUNCTION

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement