I don't have 8.4, but in later versions array_to_string ignores your NULLs, so the problem is not array_agg , it's array_to_string .
For instance:
=> select distinct state from orders; state --------- success failure
This empty string is actually NULL. Then we can see what array_agg and array_to_string do with this stuff:
=> select array_agg(distinct state) from orders; array_agg ------------------------ {failure,success,NULL} => select array_to_string(array_agg(distinct state), ',') from orders; array_to_string ----------------- failure,success
And NULL disappears in the call to array_to_string . The documentation does not indicate any specific NULL processing, but ignoring them seems reasonable, like everything else.
In version 9.x, you can get around this using COALESCE as usual:
=> select array_to_string(array_agg(distinct coalesce(state, '')), ',') from orders; array_to_string ------------------ ,failure,success
So maybe this will work for you:
array_to_string(array_agg(DISTINCT coalesce(class_low, '')), ',')
Of course, this resets NULL and empty strings to the same value, which may or may not be a problem.