# Bulk update or create

**URL:** <https://discourse.cakephp.org/t/bulk-update-or-create/6568>\
**Category:** Need Help\
**Created:** [September 2, 2019, 9:47am UTC](https://discourse.cakephp.org/t/bulk-update-or-create/6568 "2019-09-02T09:47:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bird87](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bird87/32/405_2.png) [@Bird87](https://discourse.cakephp.org/u/Bird87)\
**Post date:** [September 2, 2019, 9:47am UTC](https://discourse.cakephp.org/t/bulk-update-or-create/6568/1 "2019-09-02T09:47:10Z")

</div>

I have a huge data set that’s coming in, and I need to either update a record or create a new one using a db index.

In MySQL it would be as simple as

```
INSERT INTO table VALUES val1, val2, val3 ON DUPLICATE KEY UPDATE val1 = something;

```

However, I can’t seem to find a way to do this in CakePHP. Is there some way or do I need to use a raw query for this?

---

<div class="post-metadata">

**Author:** ![deanoj](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@deanoj](https://discourse.cakephp.org/u/deanoj)\
**Post date:** [September 3, 2019, 3:08pm UTC](https://discourse.cakephp.org/t/bulk-update-or-create/6568/2 "2019-09-03T15:08:30Z")

</div>

Having come up against the same problem, it depends on your needs. If you need the ORM features like validation, use the ORM.  
If you want pure speed, write a raw bulk insert or load a file directly into a table.

Worth a mention is that in my specific case, turning off validation and atomic inserts I got a speed boost good enough for my needs. I would pass in 500 lines of data, and save each entity in a for loop, and wrapped the entire loop in a transaction (using the begin and commit methods on the Datasource itself)
