Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Created June 6, 2017 01:31
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 EvanCarroll/cab18a61b000c3b18f3c4b71a20e1d2c to your computer and use it in GitHub Desktop.
Save EvanCarroll/cab18a61b000c3b18f3c4b71a20e1d2c to your computer and use it in GitHub Desktop.
Session 1
====
Will sleep for 5 seconds giving you time to launch TXN2.
DROP TABLE foo;
CREATE TABLE foo(x) AS
VALUES (1),(2),(3);
CREATE OR REPLACE FUNCTION test_foo_has_null()
RETURNS bool
AS
$BODY$
BEGIN
IF (SELECT count(*) = 0 FROM foo WHERE x IS NULL) THEN
PERFORM pg_sleep(5);
RETURN false;
ELSE
RETURN true;
END IF;
END;
$BODY$
LANGUAGE 'plpgsql';
BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT test_foo_has_null();
END;
Session 2
====
BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
INSERT INTO foo(x) VALUES (null);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment