debugged queries for pg