如何从单独列的嵌套 JSONB 值更新列?
How to update column from the nested JSONB value of a separate column?
我正在尝试做这样的事情:
UserActivity.update({
type: col("activity.type")
}, {
where : {
activity: { id: 4285299988 }
}
})
其中列名是“activity”,它是一个 JSONB 字段。我需要以某种方式获取嵌套的“类型”属性 并将其分配给名为“类型”的新列。
我可以找到很多关于如何在 where 子句中获取嵌套 JSONB 值的示例,但这不是我需要的。
看来我可以用 sequelize.literal 来做这个:
UserActivity.update({
type: literal(`activity ->> 'type'`)
}, {
where : {
activity: { id: 4285299988 }
}
})
这个答案虽然与更新没有特别相关,但让我走上了正确的轨道:sequelize postgres combine fn 'date' with jsonb value
我正在尝试做这样的事情:
UserActivity.update({
type: col("activity.type")
}, {
where : {
activity: { id: 4285299988 }
}
})
其中列名是“activity”,它是一个 JSONB 字段。我需要以某种方式获取嵌套的“类型”属性 并将其分配给名为“类型”的新列。
我可以找到很多关于如何在 where 子句中获取嵌套 JSONB 值的示例,但这不是我需要的。
看来我可以用 sequelize.literal 来做这个:
UserActivity.update({
type: literal(`activity ->> 'type'`)
}, {
where : {
activity: { id: 4285299988 }
}
})
这个答案虽然与更新没有特别相关,但让我走上了正确的轨道:sequelize postgres combine fn 'date' with jsonb value