pg query fix