绑定消息提供 2 个参数,但准备语句“”需要 1 个

bind message supplies 2 parameters, but prepared statement "" requires 1

这是原始查询变量

const query = `SELECT * FROM feed_items WHERE feed_item_id= AND '{}' <@ tags`

Prepared Statements 不会让你这样做,因为它太有限了。但是 pg-promise 本机格式非常灵活,您可以通过多种方式实现...

  • 通过':value' filter,您可以使用'{#}'{:value}

  • 通过Custom Type Formatting,可以直接使用</code>,同时将值包装成如下:</p> </li> </ul> <pre><code>const wrap = a => ({rawType: true, toPostgres: () => pgp.as.format('{#}', [a])});

    或者像这样:

    const wrap = a => ({rawType: true, toPostgres: () => pgp.as.format('{:value}', [a])});
    

    甚至像这样:

    const wrap = a => ({rawType: true, toPostgres: () => `'{${pgp.as.value(a)}}'`});
    

    示例:*

    await db.any('SELECT ...  <@ tags', [wrap(123)]);
    //=> SELECT ... '{123}' <@tags'