Skip to content

Instantly share code, notes, and snippets.

@felixge

felixge/init.sql Secret

Created July 22, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixge/83ad53f66a7b3cbc99e32f5326a8ff8b to your computer and use it in GitHub Desktop.
Save felixge/83ad53f66a7b3cbc99e32f5326a8ff8b to your computer and use it in GitHub Desktop.
DROP TABLE simple;
CREATE TABLE simple (
val int
);
-- After this run t1 and t2 in two different sessions, executing the SQL statements
-- in the order given by the commands after them.
--
-- Notice how t2 aborts with the error below, even so it should be serializable with t1.
--
-- ERROR: could not serialize access due to read/write dependencies among transactions
-- DETAIL: Reason code: Canceled on identification as a pivot, during commit attempt.
-- HINT: The transaction might succeed if retried.
BEGIN ISOLATION LEVEL SERIALIZABLE; -- 1
INSERT INTO simple (val) VALUES (1); -- 3
SELECT * FROM simple WHERE val = 3; -- 5
COMMIT; --7
BEGIN ISOLATION LEVEL SERIALIZABLE; -- 2
INSERT INTO simple (val) VALUES (2); -- 4
SELECT * FROM simple WHERE val = 4; -- 6
COMMIT; --8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment