insert_update on multiple rows

309 views
Skip to first unread message

Petr Peller

unread,
Jul 20, 2011, 5:33:35 AM7/20/11
to NotORM
Hello,

currently it's not possible to use insert_update method to insert/
update multiple rows in a single query. It would be handy feature. Do
you plan to implement it?

Thanks for the great lib ;-)

Jakub Vrána

unread,
Jul 20, 2011, 5:36:26 AM7/20/11
to not...@googlegroups.com
Just use:

foreach ($rows as $row) {
$db->insert_update(...);
}

I don't see any reason for doing this inside insert_update().

Jakub Vr�na

Petr Peller

unread,
Jul 20, 2011, 7:25:24 AM7/20/11
to NotORM
The reason is performance. I will execute this query often and for
high amount of rows.

Jakub Vrána

unread,
Jul 20, 2011, 8:57:24 AM7/20/11
to not...@googlegroups.com
What exactly do you want to do?

Jakub Vr�na

> The reason is performance. I will execute this query often and for
> high amount of rows.
>

Petr Peller

unread,
Jul 20, 2011, 9:12:04 AM7/20/11
to NotORM
I am inserting words into a table, but I want have every word inserted
only once (the word is the unique index of the table). Everytime an
article is inserted into DB I need to update the words table. Article
can have around 400 words. Now I use pure mySQL "INSERT ... ON
DUPLICATE KEY UPDATE" query and it works, but it would be fine if the
insert_update function could do the same.

Jakub Vrána

unread,
Jul 20, 2011, 9:14:04 AM7/20/11
to not...@googlegroups.com
What do you need to update? E.g. word count? It means the same update
for all colliding rows?

Jakub Vr�na

> I am inserting words into a table, but I want have every word inserted
> only once (the word is the unique index of the table). Everytime an
> article is inserted into DB I need to update the words table. Article
> can have around 400 words. Now I use pure mySQL "INSERT ... ON
> DUPLICATE KEY UPDATE" query and it works, but it would be fine if the
> insert_update function could do the same.
>

Petr Peller

unread,
Jul 20, 2011, 9:54:35 AM7/20/11
to NotORM
Acually I don't need to update anything (I have "word_id = word_id" in
the update statement), I only need to INSERT unique word into the
table. I could use INSERT IGNORE instead or WHERE NOT EXISTS
condition, but I think using ON DUPLICATE KEY is safer and faster.

Jakub Vrána

unread,
Jul 20, 2011, 10:06:00 AM7/20/11
to not...@googlegroups.com
Did you run any benchmarks? I think that INSERT IGNORE would be the
fastest (similar to ON DUPLICATE KEY).

I'm not going to implement it, use PDO for this task.

Jakub Vr�na

> Acually I don't need to update anything (I have "word_id = word_id" in
> the update statement), I only need to INSERT unique word into the
> table. I could use INSERT IGNORE instead or WHERE NOT EXISTS
> condition, but I think using ON DUPLICATE KEY is safer and faster.
>

Jairo Honorio

unread,
Jul 9, 2015, 3:20:29 AM7/9/15
to not...@googlegroups.com
I've just mplemented it. Please check this pull request: https://github.com/vrana/notorm/pull/105

$db->tags()->insert_multi($tags, true);
Reply all
Reply to author
Forward
0 new messages