fixing postgresql's problem with the db queries