Fix PostgreSQL Where statement