3

I'm using Postgres/sequelize .

I need to do bulkupdate and the table is partitioned , so I can't use "Insert into ~ on conflict" .

It looks like I can use bulkCreate with 'updateOnDuplicate' option but I don't know how to define multiple keys. I mean there is no pk in the table but I know two columns together will make unique records.

In this case, how to do bulkupdate ?

Model.bulkCreate(dataToUpdate, { updateOnDuplicate: ["user_id", "token", "created_at"] })
jetulis
  • 168
  • 1
  • 13
  • Are there any errors? What result do you expect? – Lin Du Apr 17 '20 at 03:55
  • It's more about HOW to do. bulkCreate doesn't seem to take any PK as argument so it looks like it implicitly use ONE pk there. But, my case, I don't have PK in the partitioned table. But, I know that I can use two columns to find a unique row. Can I still use bulkCreate (updateOnDuplicate) , If so , How? – jetulis Apr 17 '20 at 04:53

1 Answers1

1

In my case I was using json object array in my model indexes fields like name value pair which was causing issue, after updating it to array of strings fixed my issue in seqialize version 6.

indexes: [
  {
    name: "payment_clearance_pkey",
    unique: true,
    fields: ["payment_module_id", "account_id"]
  },
]
M Imran
  • 109
  • 7