Skip site navigation (1) Skip section navigation (2)

Re: xml output

From: Thom Brown <thom(at)linux(dot)com>
To: Florian Henge <florian(dot)henge82(at)web(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: xml output
Date: 2010-08-23 12:09:05
Message-ID: AANLkTikzQyUqXd_4_O9N0TtsbJ6b2wr8HgiRJAe8U6Gm@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 23 August 2010 12:33, Florian Henge <florian(dot)henge82(at)web(dot)de> wrote:

>  hi there!
>
> i wanted to ask how to get an xml output from a table like this:
>
> <words>
> <first_name>joe</first_name>
> <first_name>ian</first_name>
> <first_name>carl</first_name>
> <first_name>ben</first_name>
> </words>
>
> what i have is the following:
>
> SELECT xmlelement(name words,
>  xmlforest(nachname))
> FROM person
> SELECT
> xmlelement(name words,
> xmlforest(nachname))
> FROM person
>
> but that gives me this:
>
> <words><first_name>joe</first_name></words>
> <words><first_name>ian</first_name></words>
> <words><first_name>carl</first_name></words>
> <words><first_name>ben</first_name></words>
>
>
> thanks in advance!
>
> bye, flo
>
>
You need to use xmlagg:

SELECT
xmlelement(name words,
    xmlagg(
        xmlforest(first_name)
    )
)
FROM person

Regards
-- 
Thom Brown
Registered Linux user: #516935

In response to

  • xml output at 2010-08-23 11:33:43 from Florian Henge

Responses

pgsql-novice by date

Next:From: san manDate: 2010-08-23 22:44:09
Subject: select from pipe-delimited field
Previous:From: Krzysztof HoffmannDate: 2010-08-23 11:53:31
Subject: Re: create a box from point?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group