title: Finding the root node of a tree in Postgress
body: <p>I am using PostgreSQL and I have data in a table like this.</p>
  <pre><code>id    parent_id
  1      NULL
  2      1
  3      2
  4      NULL
  5      4
  </code></pre>
  <p>I would like to get the following result.</p>
  <pre><code>id.   root_id
  1      NULL
  2      1
  3      1
  4      NULL
  5      4
  </code></pre>
  <p>ie for each id I would like to go up the parents until I find a parent node that does not have a parent - the ultimate ancestor so to speak.</p>
  <p>Would be much obliged for some SQL-fu that solves this.</p>
  <p>Thanks!</p>