четверг, 20 октября 2016 г., 17:30:39 UTC+3 пользователь Noel Grandin 
написал:
>
>
>
> 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. 
>

Sorry, there is a typo in second insert. :(
Values should be equal to (2, 1, 1) in order to force unique constrain 
violation on DUP column.

-- 
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 [email protected].
To post to this group, send email to [email protected].
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