title: Auto generate JSON/XML from tabular sql result
body: <p>I need to generate JSON/XML from tabular result. In MS SQL Server there is built in function: FOR XML AUTO</p>
  
  <p>For example:</p>
  
  <pre><code>SELECT *
    FROM [Person] P
    LEFT JOIN CAR C ON P.id = C.PersonId
    FOR XML AUTO
  </code></pre>
  
  <p>and as a result I get (out of the box):</p>
  
  <pre><code> &lt;P id="1" Name="jan"&gt;
    &lt;C id="1" Name="toyota" Type="osobowyu" PersonId="1" /&gt;
    &lt;C id="2" Name="vw" Type="osobowyu" PersonId="1" /&gt;
  &lt;/P&gt;
  &lt;P id="2" Name="adam"&gt;
    &lt;C id="3" Name="passat" Type="test" PersonId="2" /&gt;
  &lt;/P&gt;
  &lt;P id="3" Name="piotr"&gt;
    &lt;C id="4" Name="kia" Type="test" PersonId="3" /&gt;
  &lt;/P&gt;
  </code></pre>
  
  <p>Which is very cool. I like that the nested level appears automaticaly for each JOIN. Very cool feature. </p>
  
  <p>Now I wonder if there is something similar for postgres DB?</p>
  
  <p>Thanks for any hints.</p>