GithubHelp home page GithubHelp logo

Comments (9)

lukaseder avatar lukaseder commented on June 11, 2024

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-exception

We 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.

lukaseder avatar lukaseder commented on June 11, 2024

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.

lukaseder avatar lukaseder commented on June 11, 2024

... 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.

cowwoc avatar cowwoc commented on June 11, 2024

If the ID is auto-generated, isn't it safe to assume that it does not already exist?

from jooq.

lukaseder avatar lukaseder commented on June 11, 2024

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:

  1. jOOQ knows that foo.id is the primary key (foo implements UpdatableTable)
  2. 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.

cowwoc avatar cowwoc commented on June 11, 2024

Sounds good.

from jooq.

lukaseder avatar lukaseder commented on June 11, 2024

OK. I'll close this one. It will be tracked as
#1503

from jooq.

slayful avatar slayful commented on June 11, 2024

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.

lukaseder avatar lukaseder commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.