Closed (won't fix)
Project:
Drupal core
Version:
8.0.x-dev
Component:
database system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Nov 2008 at 17:25 UTC
Updated:
29 Jul 2014 at 18:03 UTC
Jump to comment: Most recent
Comments
Comment #1
damien tournoud commentedYou are not doing anything wrong: db_merge() only supports one row queries.
Comment #2
cburschkaI see that this may not be supported currently. However, I know MySQL supports doing this in a single query. The base type MergeQuery already implements a degenerate case with multiple queries, surely adding another such case that loops over the rows would not be so bad? MySQL and other drivers that support single query multiple-record merging could then extend this.
To show the problem:
Comment #3
damien tournoud commentedIn that case ->key() should also accept multiple values.
Comment #4
Crell commentedJust how does MySQL handle multi-value insert AND merge in the same query? Is it even valid syntax? The whole reason we split out Merge queries as a separate entity is that there was no sane way I could find to fold them into insert queries without "if you call this method you can't call this other method" silliness.
Comment #5
cburschkaMight be MySQL 5.0 specific. Not sure if we require that version already.
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
Comment #6
Crell commentedhm. I'm not sure that's flexible enough for our needs. It looks like you can then only use expressions in the update portion, which is very limiting.
My gut feeling here is that this is not going to be possible with anything resembling a good generic syntax in the query builder. If you can come up with one, though, and an implementation for both MySQL and generic (Postgres and SQLite can come up with their own implementations if appropriate), then I'm OK with it.
Comment #7
Crell commentedChanging title.
Comment #9
Crell commentedComment #10
damien tournoud commentedGiven the new merge queries, this is won't fix.
Comment #11
j0rd commentedI need multi-value merge as well. I have a couple thousand rows which need to get "merged". This action happen fairly often in my website, so performing a query per row is not an option.
Probably the easiest way to implement this, would be to split it up into max 3 queries. This would be very flexible, and you could continue to use the query architecture Drupal has.
1 multi-merge would be 1 select, some PHP, then 1 multi-insert and 1 multi-update.
Comment #12
juanjo_vlc commentedIn several threads about merge querys I never read anyone talking about mysql replace syntax.
It allows replacement of multiple rows at once, but only works for full row updates.
http://dev.mysql.com/doc/refman/5.0/en/replace.html and there is not a "db_replace" function on drupal's database abstraction.