title: Postgres JOIN with unnest
body: <p>Assume I have following tables:</p>
  
  <pre><code>table: followers_arrays
  
     id   |  array
  --------+---------
      1   | {3,4,5}
  
  
  table: small_profiles
  
     id   | username |  pic    
  --------+----------+-------
      3   |   aaaa   | abcd
      4   |   bbbb   | abcd
      5   |   cccc   | abcd
  </code></pre>
  
  <p>I would like to print <em>followers_array</em> with populated data from <em>small_profiles</em> using simple JOINs.</p>
  
  <p>At first, I'm using <em>unnest</em> function like this:</p>
  
  <pre><code>SELECT id, unnest(followers_array) AS elem FROM followers_arrays 
  </code></pre>
  
  <p>And it gives me about right result:</p>
  
  <pre><code>   id   |  elem  
  --------+--------
      1   |    3
      1   |    4
      1   |    5
  </code></pre>
  
  <p>Now, from my understanding I just need to join this data to <em>small_profiles</em> ON <em>small_profiles.id</em> key like this:</p>
  
  <pre><code>SELECT id, unnest(followers_array) AS elem 
  FROM followers_arrays 
  JOIN small_profiles ON small_profiles.instagram_id = elem
  </code></pre>
  
  <p>However it seems that during JOIN, column <em>elem</em> is not created yet because I get following error:
  <em>ERROR:  column "elem" does not exist</em></p>
  
  <p>Any thoughts how should I rearrange my query?
  Thanks</p>