With H2 version 1.3.176 and newer, when using the MySQL mode, the statement in the question works. To use the MySQL mode, append ;mode=mysql
to the database URL.
سؤال
Using a H2 database, I would like to increment a value with one query. In MySQL I would go for something like
INSERT INTO counts SET id = 1, c = 1 ON DUPLICATE KEY UPDATE c = c + 1;
H2 does not support ON DUPLICATE KEY
, but I read about MERGE INTO
. However, I haven't figured out, if and how it can be used to increment a value. Is it possible? Is there another way?
المحلول
لا تنتمي إلى StackOverflow