title: postgres recursive query on the same table
body: <p>i spent almost a day on it now and it seems like i am doing something wrong.
  ok , here is the relation:
  document_urls( doc_id , url_id)</p>
  
  <p>what i want to do is to build a sorte of graph that will show all the children that has been generated from a document through on of his urls.
  example
  select * from document_urls where doc_id=1</p>
  
  <p><strong>doc_id url_id</strong><br>
  1      2<br>
  1      3</p>
  
  <p>if i select all the document with url_id=3 or 2 i will find
  select * from document_urls where url_id=2 or url_id=3</p>
  
  <p><strong>doc_id url_id</strong><br>
  1      2<br>
  1      3<br>
  2      3</p>
  
  <p>now i do the same exercise with document 2 since we covered all links of document 1 and so forth.</p>
  
  <p>here is my recursive query now</p>
  
  <pre><code>WITH  RECURSIVE generate_links(document_id,url_id) as(  
      select document_id,url_id from document_urls where document_id=1 
  UNION ALL
      select du.document_id,du.url_id from generate_links gl,document_urls du
      where gl.url_id=du.url_id 
  )
  
  SELECT * FROM generate_links GROUP BY url_id,document_id limit 10;
  </code></pre>