我想使用Sequelize迁移来更新Postgres数据库中的一个表。
我的SQL查询对JSONB列使用Postgres中的de ?运算符。
我需要运行的SQL查询是:
UPDATE messages SET type = 'products' WHERE type = 'gallery' and content ? '%textMain%'我在Sequelize中的迁移如下所示:
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkUpdate(
'messages',
{ type: 'products' },
// HERE GOES THE WHERE CLAUSE
)
},
down: async (_queryInterface, _Sequelize) => {
}
};发布于 2021-10-28 21:26:53
在掉了一些头发后寻找答案。
我这样解决了这个问题:
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkUpdate(
'messages',
{ type: 'products' },
Sequelize.literal("type = 'gallery' AND content ? 'textMain'")
)
},
down: async (_queryInterface, _Sequelize) => {
}
};希望它能帮助其他有同样问题的人!:+1
我很乐意看到解决这个问题的其他方法。
https://stackoverflow.com/questions/69761138
复制相似问题