Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't have an 8.4 handy but in more recent versions, the <code>array_to_string</code> is ignoring your NULLs so the problem isn't <code>array_agg</code>, it is <code>array_to_string</code>.</p> <p>For example:</p> <pre><code>=&gt; select distinct state from orders; state --------- success failure </code></pre> <p>That blank line is in fact a NULL. Then we can see what <code>array_agg</code> and <code>array_to_string</code> do with this stuff:</p> <pre><code>=&gt; select array_agg(distinct state) from orders; array_agg ------------------------ {failure,success,NULL} =&gt; select array_to_string(array_agg(distinct state), ',') from orders; array_to_string ----------------- failure,success </code></pre> <p>And the NULL disappears in the <code>array_to_string</code> call. The <a href="http://www.postgresql.org/docs/8.4/interactive/functions-array.html#ARRAY-FUNCTIONS-TABLE" rel="nofollow">documentation</a> doesn't specify any particular handling of NULLs but ignoring them seems as reasonable as anything else.</p> <p>In version 9.x you can get around this using, as usual, <a href="http://www.postgresql.org/docs/8.4/static/functions-conditional.html#AEN15275" rel="nofollow">COALESCE</a>:</p> <pre><code>=&gt; select array_to_string(array_agg(distinct coalesce(state, '')), ',') from orders; array_to_string ------------------ ,failure,success </code></pre> <p>So perhaps this will work for you:</p> <pre><code>array_to_string(array_agg(DISTINCT coalesce(class_low, '')), ',') </code></pre> <p>Of course that will fold NULLs and empty strings into one value, that may or may not be an issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload