postgres query bux fixing.