我尝试使用双引号,单引号,转义引号,无引号,围绕CASE中的值,但每次运行迁移时都会有syntax error at or near "'example'"
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.resolve()
// ... Removed for brevity
.then(() => queryInterface
.addColumn(...)
)
.then(() =>
Sequelize.sequelize.query(
'UPDATE TableName SET TableName.status=CASE ' +
'WHEN TableName.status_old IS \'example\' THEN \'example2\' ' +
'ELSE TableName.status_old END'
)
)
.then(() => queryInterface
.addColumn(...)
);
},
down: (queryInterface, Sequelize) => {
// ... Removed for brevity
}
};
答案 0 :(得分:1)
你的问题是IS
,PostgreSQL不知道它是什么。您想要一个简单的=
比较:
'UPDATE TableName SET TableName.status=CASE ' +
'WHEN TableName.status_old = \'example\' THEN \'example2\' ' +
'ELSE TableName.status_old END'