Postgres-如果没有更新,则返回查询值

我正在使用node-postgres进行一些更新,并且我希望返回未找到匹配项的任何值,因此我们知道什么不起作用,这就是我所拥有的:

let query = `
update ticket_custom_field t set
value = $1
where t.ticket_id = $2 AND t.custom_field_id = $3
returning $3 as "custom_field_id",$1 as "value";`;

results = await Promise.all(
    custom_fields.map(cf => client.query(query,[cf.value,ticket_id,cf.custom_field_id]))
);

这在字段确实更新时有效:

"rows": [
    {
        "custom_field_id": 1,"value": "x1"
    }
],"fields": [
    {
        "name": "custom_field_id","tableID": 0,"columnID": 0,"dataTypeID": 23,"dataTypeSize": 4,"dataTypeModifier": -1,"format": "text"
    },{
        "name": "value","dataTypeID": 25,"dataTypeSize": -1,"format": "text"
    }
],

,但是当没有更新(例如,找不到字段ID)时,行数组为空。我有fields数组,但是并没有告诉我哪个更新失败,而无需手动分析结果并在之前/之后进行比较。

bobo3324 回答:Postgres-如果没有更新,则返回查询值

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162636.html

大家都在问