title: How to concatenate field values with recursive query in postgresql?
body: <p>I have a table in PostgreSQL database that contains parts of addresses in a form of a tree and looks like this:</p>
  
  <pre><code>Id | Name         | ParentId
  1  | London       | 0
  2  | Hallam Street| 1
  3  | Bld 26       | 2
  4  | Office 5     | 3
  </code></pre>
  
  <p>I would like to make a query to return an address, concatenated from all ancestor names. I need the result table to be like this:</p>
  
  <pre><code>Id | Address
  1  | London
  2  | London, Hallam Street
  3  | London, Hallam Street, Bld 26
  4  | London, Hallam Street, Bld 26, Office 5
  </code></pre>
  
  <p>I guess I have to use <code>WITH RECURSIVE</code> query, but all the examples I've found use the where clause, so I have to put <code>WHERE name='Office 5'</code> to get the result only for that particular row. But I need a concatenated address for each row of my initial table. How can this be done?</p>