Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top