remove redundant transaction; avoid field reference in subquery from clause to work with pg 9.1