title: There is an entry for table "a", but it cannot be referenced from this part of the query
body: <p>I wrote a query which will generate sub periods from an existant periods in a table named <code>allotment</code>:</p>
  
  <pre><code>select a.product_id, 
  daterange((lower(a.allotment_period) + concat(n.i - 1, ' days')::interval)::date, 
  (upper(a.allotment_period) + concat(n.i, ' days')::interval)::date, '[]') 
  from test.allotment as a
  cross join(select * from generate_series(1, a.period_length)) as n(i)
  where a.id = 2 
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>ERROR: invalid reference to FROM-clause entry for table "a" LINE 5: cross `join(select * from generate_series(1, a.period_length)... ^ HINT: There is an entry for table "a", but it cannot be referenced from this part of the query. SQL state: 42P01 Character: 250`
  </code></pre>
  
  <p>I found a similar question <a href="https://stackoverflow.com/questions/38750599/sql-joins-there-is-an-entry-for-table-but-it-cannot-be-referenced?rq=1">SQL joins, “there is an entry for table but it cannot be referenced”</a> but it doesnt resolve my problem. Any one has a solution for this problem?</p>