title: Postgres query shuffles values in double precision[] when using WHERE condition
body: <p>I have a view that I am querying where the query provides a mix of results depending on the conditions that are included.  The table retrieves the stock symbol, close price (cc), EMA20, and EMA50.  The close, EMA20, and EMA50 are double precision arrays where the value at first index corresponds to the more recent timevalue.</p>
  <p>Without any conditions:</p>
  <ul>
  <li><p>close price array is stored as <code>[186.17, 185.94, 181.84, 178.94, 176.47]</code></p>
  </li>
  <li><p>EMA20 array is stored as <code>{177.781517686655,176.898519548408,175.94678476403,175.326446318138,174.946072246363}</code></p>
  </li>
  <li><p>EMA50 array is stored as <code>{173.328052542577,172.803891421866,172.267723724799,171.877018570709,171.588733614412}</code></p>
  </li>
  </ul>
  <p>When the following query is used, the values of the arrays are shuffled and provides results that should not be returned if the correct array values were evaluated.</p>
  <pre><code>SELECT ticker, exchange, cc, EMA20, EMA50
  FROM symbolsview
  WHERE 
      exchange IN('NYSE', 'NASDAQ', 'AMEX')
      AND (EMA20[1] &gt; EMA50[1])
      AND ((cc[1] &lt;= EMA50[1]) OR (ll[1] &lt;= EMA50[1]))
      AND (cc[2] &gt;= EMA50[2])
  </code></pre>
  <p>When I run this query, the values for the same symbols are:</p>
  <ul>
  <li>close:  <code>{176.47,178.94,186.17,185.94,181.84}</code></li>
  <li>EMA20: <code>{174.946072246363,175.326446318138,177.781517686655,176.898519548408,175.94678476403}</code></li>
  <li>EMA50: <code>{171.588733614412,171.877018570709,173.328052542577,172.803891421866,172.267723724799}</code></li>
  </ul>
  <p>The values for these columns have been shifted for some reason.  Also when I add another criteria 'AND ticker = 'XXX' where XXX is the ticker value, no results are shown where without this additional criteria showed up in the query results.  If I query the view without any conditions, the arrays are returned with values in the correct order.</p>
  <p>There is a table that contains values in a JSON[] column.  The stored view creates the the close, EMA20, and EMA50 double precision from a JSON[].   The view extracts the values and performs an array_agg.  See code below.</p>
  <pre><code>SELECT ticker, 
          array_agg(obj-&gt;&gt;'EMA20')::float[] as EMA20,
          array_agg(obj-&gt;&gt;'EMA50')::float[] as EMA50,
          array_agg(obj-&gt;&gt;'low')::float[] as ll, 
          array_agg(obj-&gt;&gt;'close')::float[] as cc
          FROM symbols, jsonb_array_elements(symbols.last5stats) obj
  </code></pre>
  <p>Any insight on why the arrays are being shuffled would be helpful.</p>