Fixup PostgreSQL queries