Comments (9)
Yes, simulation of these clauses using multiple statement execution is on
the roadmap.
Any hints with respect to how these MySQL extensions could be formally
simulated in H2 are very welcome
Cheers
Lukas
Am Mittwoch, 13. Juni 2012 schrieb cowwoc <
[email protected]
:
JOOQ doesn't support insert.onDuplicateKeyIgnore() for H2, nor does it
allow INSERT ... WHERE NOT EXISTS as mentioned here:
http://stackoverflow.com/questions/6736518/h2-java-insert-ignore-allow-exceptionWe need a way to insert a new row, unless it already exists (this is the
counterpart to MERGE support).
Reply to this email directly or view it on GitHub:
#19
from jooq.
INSERT .. ON DUPLICATE KEY IGNORE will be simulated in one of the next version of jOOQ. This will be tracked as #1503:
https://sourceforge.net/apps/trac/jooq/ticket/1503
Already now, you can write
create.insertInto(TABLE)
.select(yourSelectStatement)
from jooq.
... actually, the solution suggested by Thomas Mueller doesn't work for all insert statements. If the ID (or any other unique key value) is auto-generated, then the subselect cannot be used correctly...
Any other ideas for a formal simulation of INSERT .. ON DUPLICATE KEY IGNORE?
from jooq.
If the ID is auto-generated, isn't it safe to assume that it does not already exist?
from jooq.
Hmm, let's re-think this. I might've gotten something wrong. This is what Thomas Mueller suggests (more or less):
INSERT INTO foo
SELECT 123 AS id, 'abc' AS value
WHERE NOT EXISTS (SELECT 1 FROM foo WHERE id = 123)
Now, this works only if:
- jOOQ knows that foo.id is the primary key (foo implements UpdatableTable)
- foo.id is supplied with the insert statement (and not overridden by some auto-increment value)
If both 1) and 2) can be guaranteed, then jOOQ can indeed simulate the ON DUPLICATE KEY IGNORE clause for all remaining dialects, including H2. If checking 1) and 2) fails, jOOQ will throw an exception.
from jooq.
Sounds good.
from jooq.
OK. I'll close this one. It will be tracked as
#1503
from jooq.
Hi there!
I don't believe this issue finally got addressed by the referenced tickets.
46074ed seems to be addressing only sqlite:
I've tried latest H2 and jOOQ versions with H2 compliant mode without any any luck.
Trying to run with SQLITE compliant mode gets me this:
! org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT OR[*] IGNORE INTO <db-name>.<table-name> (<columns>) VALUES (?, ?, ?) "; expected "INTO"; SQL statement:
Any plans for addressing this issue for H2? We're using H2 for integration tests and this is basically all we're missing to test everything conveniently. :)
from jooq.
Hi @slayful, this is a very old issue, and I'm sure it was implemented as good as possible at the time, but certainly, you may have run into some other problem. Would you mind creating a new issue with:
- Some example code that you wrote
- The expected behaviour
- The actual behaviour
Thanks
from jooq.
Related Issues (20)
- Wrong source code generated when newline escape sequence of long view source is split into two HOT 3
- Wrong source code generated when newline escape sequence of long view source is split into two - Merge [#16662]
- Wrong source code generated when newline escape sequence of long view source is split into two - Merge [#16662]
- Wrong source code generated when newline escape sequence of long view source is split into two - Merge [#16662]
- Add SQLite support for GROUP_CONCAT(DISTINCT ..) HOT 1
- Generate DAO.fetchOneByXYZ for unique columns missing with SQLite HOT 6
- Hangs after several iterations of a SELECT query that retrieves about 200 items in R2DBC. HOT 1
- Add jakarta.annotation.Generated as possible GeneratedAnnotationType
- Cannot insert varchar[] column value using jooq HOT 2
- Update using multi-column set clause with DSL.row and custom type logs warn on deprecated static type registry - Merge [#16627]
- Update using multi-column set clause with DSL.row and custom type logs warn on deprecated static type registry - Merge [#16627]
- Update using multi-column set clause with DSL.row and custom type logs warn on deprecated static type registry - Merge [#16627]
- SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints HOT 6
- SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints - Merge [#16675]
- SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints - Merge [#16675]
- SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints - Merge [#16675]
- Wrong title in manual section "alter-table-drop-foreign-key" HOT 1
- Support Oracle 23ai's DEFAULT ON NULL clauses
- Add dynamic TOC to manual pages
- Add a Settings.parserJDBCEscapeSyntax
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jooq.