5

I know there is no support for updateOnDuplicate for postgresQL by Sequelize sequelize doc, so is there a work around for this?

Can it be implemented via "SQL command".

Melroy Fernandes
  • 371
  • 1
  • 5
  • 16

2 Answers2

5

New sequelize (v5) includes updateOnDuplicate feature for all dialects

Fields to update if row key already exists (on duplicate key update)? (only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >= 9.5). By default, all fields are updated.

Check here : Docs

You can use as

model.bulkCreate(dataToUpdate, { updateOnDuplicate: ["user_id", "token", "created_at"] })
2

There is some work around. See upsert function. When used in Postgresql it creates custom function in database. Unfortunately there is no bulkUpsert, so you either use it in some for-loop or execute raw SQL as suggested here.

sawim
  • 1,032
  • 8
  • 18