Re: XML output & multiple SELECT queries

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: Peter Billen <peter(at)clueless(dot)be>
Subject: Re: XML output & multiple SELECT queries
Date: 2008-06-15 16:49:45
Message-ID: 200806151849.46822.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Billen wrote:
> I would like to ask a question about outputting data as XML. Say I have two
> tables:
>
> team(integer id, text name);
> player_of_team(integer id, integer team_id, text name); (team_id is FK to
> team.id)
>
> I would like to query both tables to get following example XML output:
>
> <team name="Real Madrid">
>      <players>
>          <name>Garcia</name>
>          <name>Robinho</name>
>      </players>
> </team>

SELECT XMLElement(name team, XMLAttributes(team.name as name), XMLElement(name
players, XMLAgg(XMLElement(name name, player_of_team.name)))) FROM team JOIN
player_of_team ON team.id = player_of_team.team_id GROUP BY team.name;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Tregea 2008-06-15 23:27:05 PostgreSQL and AMD?
Previous Message Thomas Kellerer 2008-06-15 14:36:03 Re: Need Tool to sync databases with 8.3.1