On 2016/10/19 2:24 PM, Filipp Zhinkin wrote:

Suppose we have following table:

CREATE TABLE test_table (
  id INT,
  dup INT,
  counter INT,
  UNIQUE(dup),
  PRIMARY KEY(id)
);

I'm expecting to observe counter == 2 after following statements being executed:

INSERT INTO test_table (id, dup, counter) VALUES (1, 1, 1);
INSERT INTO test_table (id, dup, counter) VALUES (2, 2, 2) ON DUPLICATE KEY 
UPDATE counter = counter + VALUES(counter);

But counter's value for row with id == 1 may still be 1.


Are you sure you meant to write the test like this?
Because you have ID as the primary key, which means after the two INSERTS, the 
table should look like:

select * from test_table;
ID      DUP     COUNTER
1       1       1
2       2       2

Because the second insert is using a different ID, which means that the "ON 
DUPLICATE KEY" logic does not trigger.

And H2 appears to correctly handle this.

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to