Debian Codegraph @

src/test/isolation/specs/insert-conflict-do-update-2.spec

raw
1 # INSERT...ON CONFLICT DO UPDATE test
2 #
3 # This test shows a plausible scenario in which the user might wish to UPDATE a
4 # value that is also constrained by the unique index that is the arbiter of
5 # whether the alternative path should be taken.
6
7 setup
8 {
9 CREATE TABLE upsert (key text not null, payload text);
10 CREATE UNIQUE INDEX ON upsert(lower(key)) INCLUDE (payload);
11 }
12
13 teardown
14 {
15 DROP TABLE upsert;
16 }
17
18 session s1
19 setup
20 {
21 BEGIN ISOLATION LEVEL READ COMMITTED;
22 }
23 step insert1 { INSERT INTO upsert(key, payload) VALUES('FooFoo', 'insert1') ON CONFLICT (lower(key)) DO UPDATE set key = EXCLUDED.key, payload = upsert.payload || ' updated by insert1'; }
24 step c1 { COMMIT; }
25 step a1 { ABORT; }
26
27 session s2
28 setup
29 {
30 BEGIN ISOLATION LEVEL READ COMMITTED;
31 }
32 step insert2 { INSERT INTO upsert(key, payload) VALUES('FOOFOO', 'insert2') ON CONFLICT (lower(key)) DO UPDATE set key = EXCLUDED.key, payload = upsert.payload || ' updated by insert2'; }
33 step select2 { SELECT * FROM upsert; }
34 step c2 { COMMIT; }
35
36 # One session (session 2) block-waits on another (session 1) to determine if it
37 # should proceed with an insert or update. The user can still usefully UPDATE
38 # a column constrained by a unique index, as the example illustrates.
39 permutation insert1 insert2 c1 select2 c2
40 permutation insert1 insert2 a1 select2 c2