Fixed query for postgres with parameterization