【问题标题】:Unable to fathom node-postgres error无法理解 node-postgres 错误
【发布时间】:2015-05-25 10:44:53
【问题描述】:

使用 node-postgres,以下 sn-p 可以正常工作:

let shift_solutions = function (ufrom, uto) {
    let cmd = 'update solutions set "user" = \''+uto+'\' where "user" = \''+ufrom+'\''
    client.query( cmd, null, function (err,rslt) { 
        ... works

但如果我将上面的内容更改为:

    client.query('update solutions set "user" = %2 where "user" = %1',
                 [ufrom,uto], 
                 function (err,rslt) { 
        ... fails

yields - 未处理的拒绝错误:“%”处或附近的语法错误。

我怀疑这可能与用户字段的类型为“uuid”这一事实有关,但并没有真正的线索。参数以字符串形式提供:

[ '8e479385-5692-4acc-8dd7-4630480bd17f',
  '0cc0832e-1f01-40a9-aaa4-30ae8e56d708' ]

任何人都能够阐明我在这里做错了什么?谢谢。

【问题讨论】:

    标签: postgresql node-postgres


    【解决方案1】:

    使用美元符号作为参数,即

    client.query('update solutions set "user" = $2 where "user" = $1'
    

    【讨论】:

    • 我是个白痴。很明显,我需要睡一觉...... 8-( 很抱歉浪费了你的时间......
    • 哈哈,没问题,每个人都会遇到
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多