Fixed some queries with the newer PostgreSQL code