Re: XML output & multiple SELECT queries - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: XML output & multiple SELECT queries
Date
Msg-id 200806151849.46822.peter_e@gmx.net
Whole thread Raw
In response to XML output & multiple SELECT queries  (Peter Billen <peter@clueless.be>)
List 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;

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Need Tool to sync databases with 8.3.1
Next
From: "John Tregea"
Date:
Subject: PostgreSQL and AMD?