Join GitHub today
SQL : Merge query support #7
Provide a merge query that will work on DBMSs that do not support merge. It would work by using the data entered into the columns() and values() methods to generate a where clause automatically. An ID would be entered in the key() method and that data would be used to generate the Querydsl list() request. When a list of IDs is returned that list would be used to generate an update statement. The values that are not in the list of IDs would be used to generate an insert statement. The whole operation would return a unified list of IDs from the update command and the insert command. Many times, a merge command is used to insert or update a single record so it is mostly a convenience to write the lookup and update in one command.
Timo Westkämper (timo-westkamper) on 2010-06-15
As the signature for returning the generated keys something like this?
I commited an implementation that works with H2. The UPDATE + INSERT combo for other engines follows soon.
Please comment here if the direction is ok.
This will be great. Very excited about this one. It can get a little tricky with exclusion joins (leftJoin(b)... where(b.col1.isNull()). If you want some ideas on how I have been doing this, let me know.
I just commited a version with basic support for MERGE INTO for other databases. It works like this
Subquery usage is not yet supported for the simulated MERGE INTO. I believe for the subquery part your flow could be used.
Could you provide a concrete example? I haven't used MERGE INTO before, so I am not familiar with MERGE INTO + subquery combos.
I am working on a patch that will make an automatic left join complement query. It will allow for updates and inserts of multiple records on the same merge. I'll submit it tomorrow.
Any progress with the patch?
I'm moving house until Sunday. I will submit my patch early next week.
What's up with the patch? Did the harddisk eat it? ;)
I will be out of the office starting 21/07/2010 and will not return until
I still have no Internet at my new place. Who knew moving across
On Sat, Jul 31, 2010 at 4:39 AM, Timo Westkämper
McKinley, any changes to your internet connectivity? I am fixing issues to be able to release Querydsl 2.0 in a few weeks. If you want you can also post an informal patch as a code snippet or describe how you did it.
Yes, I am finally getting around to side projects again after to much
What's the status on this one? It would be great to get it into Querydsl 2.0.1.
McKinley, do you still have the patch for this one?
Yes, I'm getting back into the patching mode so that I can submit it. I'll
On Wed, Jan 19, 2011 at 12:17 PM, Timo Westkämper <
Three months later, any update? :)
SQLMergeClause.executeWithKey() doesn't seem to exist. How are we supposed to get auto-generated keys inserted by a merge operation?
I stand corrected. It seems it isn't possible to MERGE into tables with AUTO_INCREMENT columns unless you explicitly specify their value. Therefore executeWithKey() is never needed. Source: http://stackoverflow.com/questions/6306592/merge-into-table-containing-auto-increment-columns
Can you please reopen this issue? We need to revise the API in response to an updated answer: http://stackoverflow.com/a/6307884/14731
This demonstrates that it is possible to MERGE into tables containing AUTO_INCREMENT columns without specifying their value. In the above example, it's not clear how to get the generated customer.id using QueryDSL. Currently,