0

I've tried double quotes, single quotes, escaped quotes, no quotes, around the values in the CASE, but each time I run the migration there is a 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
  }
};

1 Answer 1

1

Your problem is that IS, PostgreSQL doesn't know what that it is. You want a simple = comparison:

'UPDATE TableName SET TableName.status=CASE ' +
'WHEN TableName.status_old = \'example\' THEN \'example2\' ' +
'ELSE TableName.status_old END'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.