I read the
Lock documentation, and the relevant passage for me
seems to be
...if a transaction is going to change data in a table, then SHARE
ROW EXCLUSIVE lock mode should be acquired to prevent deadlock
conditions when two concurrent transactions attempt to lock the table
in SHARE mode and then try to change data in this table, both
(implicitly) acquiring ROW EXCLUSIVE lock mode that conflicts with a
concurrent SHARE lock.
So basically when only a single table is involved, the only way to
get a deadlock is when you have a transaction containing both selects
and dml on it?
How about with subselects? If I have one transaction containing
update foo set ... where id in (select foo_id from bar)
could that deadlock with
insert into bar values (...)
?