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

Add partial support for INSERT IGNORE in MySQL mode #824

Merged
merged 1 commit into from
Jan 31, 2018

Conversation

katzyn
Copy link
Contributor

@katzyn katzyn commented Jan 31, 2018

Limitations:

  1. Only duplicate key errors are ignored. MySQL also ignores other errors, but generates warnings for them. For duplicate key error there are no warnings in MySQL and in this implementation too.

  2. I didn't test behaviour of MySQL when both IGNORE and ON DUPLICATE KEY UPDATE are specified. This implementation allows, but otherwise ignores IGNORE if ON DUPLICATE KEY UPDATE was also specified.

We have issue #455 for INSERT IGNORE, but this issue does not mention which parts of IGNORE are desired.

Only duplicate key errors are ignored.
@katzyn
Copy link
Contributor Author

katzyn commented Jan 31, 2018

I just checked latest MariaDB from its console. It doesn't count duplicate rows separately, but counts them as warnings. However, overall status and count of affected rows are still the same.

@grandinj grandinj merged commit cad0c35 into h2database:master Jan 31, 2018
@katzyn katzyn deleted the insert_ignore branch January 31, 2018 08:15
@fankaidev
Copy link

this is very helpful!

@ramsestom
Copy link

ramsestom commented Dec 21, 2018

I tried to use the INSERT IGNORE statement with the latest version of H2 JDBC driver (1.4.197) but it do not seem to work.
For example if I do:
INSERT IGNORE INTO accounts (id, email) VALUES (1, 'test@yahoo.fr');
I have this error message:
Syntax error in SQL statement {0}; expected {1}; SQL statement
Whereas if I do a simple insert like
INSERT INTO accounts (id, email) VALUES (1, 'test@yahoo.fr');
everything works as expected (I have a duplicate key exeption if this record is already in the db else it is correctly inserted)

My accounts test table is defined like this:

CREATE TABLE IF NOT EXISTS accounts (
	id INTEGER PRIMARY KEY AUTO_INCREMENT,
	email VARCHAR NOT NULL,
	CONSTRAINT email_unique UNIQUE (email)
);

Any idea of what might cause this issue?

@katzyn
Copy link
Contributor Author

katzyn commented Dec 21, 2018

INSERT IGNORE is not supported in Regular mode, you have to enable MySQL compatibility mode explicitly by appending ;MODE=MySQL to your database URL or by executing SET MODE MySQL statement.

Many messages in French localization were broken for a long time, this issue was fixed after 1.4.197 release. If you want to get correct error messages you need to build H2 from its current sources.

@ramsestom
Copy link

Thanks. using the ;MODE=MySQL flag fixed the problem

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

Successfully merging this pull request may close these issues.

None yet

4 participants