Is it possible to prevent Phantom from reading or otherwise block the missing row in a Postgres transaction? For example, consider the following sequence of commands:
When connecting 1:
CREATE TABLE weather ( city varchar(80) PRIMARY KEY ); BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; INSERT INTO weather VALUES ('a');
Meanwhile, with compound 2:
BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; SELECT * FROM weather WHERE city = 'a' FOR SHARE; INSERT INTO weather VALUES ('b');
And back to compound 1:
COMMIT;
And again, back to compound 2:
COMMIT; SELECT * FROM weather;
It would seem impossible for the transaction on connection 2 to be successful, since the precondition for creating row "b" depended on the absence of row "a". How to prevent the successful completion of the second transaction?
source share