-- generate a serialization error.
BEGIN ISOLATION LEVEL SERIALIZABLE;
SELECT NEXTVAL('pgbench_deadlock_seq') AS myid \gset
\set odd :myid % 2 = 1
\if :odd
-- wait for EVEN to get its id as well
CALL pgbench_deadlock_wait(:myid+1);
SELECT * FROM pgbench_deadlock_data WHERE cid = 1;
-- barrier
SELECT NEXTVAL('pgbench_deadlock_seq');
CALL pgbench_deadlock_wait(:myid+3);
UPDATE pgbench_deadlock_data SET myid = :myid WHERE cid = 2;
\else
-- EVEN
SELECT * FROM pgbench_deadlock_data WHERE cid = 2;
-- barrier
SELECT NEXTVAL('pgbench_deadlock_seq');
CALL pgbench_deadlock_wait(:myid+2);
UPDATE pgbench_deadlock_data SET myid = :myid WHERE cid = 1;
\endif
-- RESET 
\set i debug(:myid)
COMMIT;
