Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H2 support for INSERT IGNORE #186

Closed
dcapwell opened this issue Oct 26, 2017 · 6 comments
Closed

H2 support for INSERT IGNORE #186

dcapwell opened this issue Oct 26, 2017 · 6 comments
Assignees
Labels

Comments

@dcapwell
Copy link

java.lang.UnsupportedOperationException: There's no generic SQL for INSERT IGNORE. There must be vendor specific implementation

	at org.jetbrains.exposed.sql.vendors.VendorDialect.insert(Default.kt:241)
	at org.jetbrains.exposed.sql.vendors.H2Dialect.insert(H2.kt:44)
	at org.jetbrains.exposed.sql.statements.InsertStatement.prepareSQL(InsertStatement.kt:43)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_main(Statement.kt:46)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:103)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:97)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:27)
	at org.jetbrains.exposed.sql.QueriesKt.insertIgnore(Queries.kt:72)

I tried out Exposed because I needed to support both H2 and Postgres, and wanted the ability to do a logical insert if not exists, which is different for both DBs; below is the code I tried to write

private val clusterId: Int = transaction {
            Clusters.insertIgnore {
                it[name] = this@ExposedCluster.name
            }

            // name has a unique constraint so first() is safe
            Clusters.slice(Clusters.name).selectAll().first()[Clusters.id]
        }

My guess at what insertIgnore means was insert if not exists so expected the H2 version to produce a MERGE statement as follows

MERGE INTO CLUSTERS(name) KEY(name) VALUES('$name')
@Tapac
Copy link
Contributor

Tapac commented Oct 30, 2017

@dcapwell, MERGE has different semantic then INSERT IGNORE and is more like a REPLACE.
ATM replace also doesn't work with H2, but i guess it's possible to fix both cases (insertIgnore = insert..on duplicate key update, replace = merge)

@Tapac Tapac added the bug label Oct 30, 2017
@Tapac Tapac self-assigned this Oct 30, 2017
@coderfengyun
Copy link

@Tapac how can i config "(insertIgnore = insert..on duplicate key update, replace = merge)"
?

@cdietze
Copy link

cdietze commented May 7, 2018

FWIW, H2 supports INSERT IGNORE since Version 1.4.197 (2018-03-18), see changelog.

@spyro2000
Copy link

Still getting error on IGNORE with 1.4.200...

@micHar
Copy link

micHar commented Apr 26, 2022

Oh, just came to mention that I also get that on 1.4.199.

Specifically:

org.jetbrains.exposed.exceptions.UnsupportedByDialectException: INSERT IGNORE supported only on H2 v1.4.197+ with MODE=MYSQL., dialect: h2.

Postgre supports insert ignore for some time, is there a reason it's only supported with mysql?

@Rubyj
Copy link

Rubyj commented May 5, 2022

@Tapac same for me as the comment above ^ any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants