Curt Sampson <cjs(at)cynic(dot)net> writes:
> But why does session 2 hang
> in this instance?
Because the sub-SELECT sees a snapshot of transactions that were already
committed at the start of session 2's transaction. If session 1 hasn't
committed yet, the EXISTS will return false. The actual INSERT will
notice the inserted-but-not-yet-committed row, and will block waiting to
see whether it gets committed or not.
regards, tom lane