准备好的语句无法识别 Postgres JS 绑定上的任何参数

Prepared Statement doesn't recognize any parameters on Postgres JS binding

我正在尝试同时更新多行。 为此,我正在制作以下准备好的声明:

WITH new_values (id, data, email) AS (
  VALUES (, , ), (, , ), (, , ), (, , )
)
UPDATE prospects
  SET 
    data = new_values.data,
    email = new_values.email
  FROM new_values
  WHERE
    prospects.id = new_values.id
  RETURNING *

但我收到以下错误:

error: bind message supplies 12 parameters, but prepared statement "prospects-multi-update" requires 0
api-prospects_1       |     at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:546:11)
api-prospects_1       |     at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:371:19)
api-prospects_1       |     at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:114:22)
api-prospects_1       |     at Socket.emit (events.js:180:13)
api-prospects_1       |     at addChunk (_stream_readable.js:274:12)
api-prospects_1       |     at readableAddChunk (_stream_readable.js:261:11)
api-prospects_1       |     at Socket.Readable.push (_stream_readable.js:218:10)
api-prospects_1       |     at TCP.onread (net.js:581:20)

我尝试了不同的查询(使用 INSERT ... ON CONFLICT DO UPDATE),但效果相同。

它仅适用于直接 INSERT INTO 查询。


编辑

调用此查询的代码如下: (我删除了字符串生成函数,因为它不是很有用)

const upsertValues = async (entities) => {
  if (entities.length === 0) return []

  const client = pool.connect()

  const values = [...]
  const variables = [...]
  const setStatements = [...]

  const res = await client.query({
    name: `${resourceName}-multi-update`,
    test: `
      WITH new_values (id, ${columns}) AS (
        VALUES ${variables}
      )
      UPDATE prospects
        SET ${setStatements}
        FROM new_values
        WHERE
          prospects.id = new_values.id
        RETURNING *
    `,
    values: flatten(values),
  })

  return res.row || []
}

错误是由于属性 text prepared statement 被错误命名为test,所以引擎甚至找不到查询字符串。