title: How to get index of an array value in PostgreSQL?
body: <p>I have a table called <code>pins</code> like this:</p>
  
  <pre><code>id (int) |      pin_codes (jsonb)
  --------------------------------
  1        |  [4000, 5000, 6000]
  2        |  [8500, 8400, 8600]
  3        |  [2700, 2300, 2980]
  </code></pre>
  
  <p>Now, I want the row with pin_code <code>8600</code> and with its array index. The output must be like this:</p>
  
  <pre><code>     pin_codes       |  index
  ------------------------------
  [8500, 8500, 8600]   |   2
  </code></pre>
  
  <p>If I want the row with pin_code <code>2700</code>, the output :</p>
  
  <pre><code>     pin_codes       |  index
  ------------------------------
  [2700, 2300, 2980]   |   0
  </code></pre>
  
  <p>What I've tried so far:</p>
  
  <pre><code>SELECT pin_codes FROM pins WHERE pin_codes @&gt; '[8600]'
  </code></pre>
  
  <p>It only returns the row with wanted value. I don't know how to get the index on the value in the pin_codes array!</p>
  
  <p>Any help would be great appreciated.</p>
  
  <p>P.S:</p>
  
  <p>I'm using PostgreSQL 10</p>