title: Trying to query a JSON array of non-objects in Postgresql 9.3
body: <p>I'm trying to query a table with a JSON column which will always hold an array of "primitive" values (i.e. integers, strings, booleans -- not objects or arrays).</p>
  
  <p>My query should be similar to [ref2], but I can't do <code>-&gt;&gt;'id'</code> because I'm not trying to access a JSON object but the value itself.</p>
  
  <p>In the [ref1] fiddle (blatant fork from the above), there's and incomplete query... <em>I'd like to query all <code>things</code> which contain <code>3</code> among its values</em>.</p>
  
  <p>Even more so, I'd like some rows to have arrays of strings, other rows to have arrays of integers, and other ones arrays of booleans... So casting is undesiderable.</p>
  
  <p>I believe <code>-&gt;&gt;</code> returns the original JSON value type, but I need the "root" object... That is, my JSON value is <code>[1,2,3,4]</code>, using <code>json_array_elements</code> should yield e.g. <code>2</code>, but that is a JSON type according to my tests.</p>
  
  <p>Upgrading to 9.4 is planned in the near future, but I haven't read anything yet that gave me a clue <code>jsonb</code> would help me.</p>
  
  <p>UPDATE: at the moment, I'm (1) making sure all values are integers (mapping non-integers values to integers), which is suboptimal; (2) querying like this:</p>
  
  <pre><code>SELECT *
    FROM things, json_array_elements(things.values) AS vals
    WHERE vals.value::text::integer IN (1,2,3);
  </code></pre>
  
  <p>I need the double casting (otherwise it complains that <code>cannot cast type json to integer</code>).</p>
  
  <p>ref1: <a href="http://sqlfiddle.com/#!15/5febb/1" rel="nofollow noreferrer">http://sqlfiddle.com/#!15/5febb/1</a></p>
  
  <p>ref2: <a href="https://stackoverflow.com/questions/24733196/how-to-query-an-array-of-json-in-postgresql-9-3">How to query an array of JSON in PostgreSQL 9.3?</a></p>