title: Google BigQuery: position of element in array
body: <p>Is it possible get the position of element in array in Google BigQuery?
  Something like array_postion function in Postgresql?</p>
  <p>In particular I need to get the array position of element after unnest array:</p>
  <pre><code>WITH data_table AS
  (SELECT '{&quot;fruit&quot;:[{&quot;apples&quot;:5,&quot;oranges&quot;:10},{&quot;apples&quot;:2,&quot;oranges&quot;:4}]}' AS data)
  
  SELECT fruit, ? as position
  FROM data_table, UNNEST(JSON_EXTRACT_ARRAY(  data,  '$.fruit')) as fruit
  
  fruit                     |  position
  -------------------------------------
  {&quot;apples&quot;:5,&quot;oranges&quot;:10} |  1
  {&quot;apples&quot;:2,&quot;oranges&quot;:4}  |  2
  </code></pre>
  <p>I try a workaound using row_number(), but I'm not sure about sorting</p>
  <pre><code>WITH data_table AS
  (SELECT '{&quot;fruit&quot;:[{&quot;apples&quot;:5,&quot;oranges&quot;:10},{&quot;apples&quot;:2,&quot;oranges&quot;:4}]}' AS data)
  
  SELECT fruit, ROW_NUMBER() OVER() AS position
  FROM data_table, UNNEST(JSON_EXTRACT_ARRAY(  data,  '$.fruit')) as fruit
  </code></pre>