xml

Started by Ramesh Tabout 11 years ago4 messagesgeneral
Jump to latest
#1Ramesh T
rameshparnanditech@gmail.com

Hi all,
SELECT xmlagg(xmlelement(
name actor, xmlattributes(first_name)
)ORDER BY actor_id,',')from actor;

the above code return following result,

[image: Inline image 1]
Question :

i want retrieve result from above XML result like
penelope,nick,jennifer,jhony,,,,,

xpath is their but unable to fix this query.

any help how to get only names from query not xml.

Attachments:

image.pngimage/png; name=image.pngDownload
#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Ramesh T (#1)
Re: xml

2015-03-23 12:40 GMT+01:00 Ramesh T <rameshparnanditech@gmail.com>:

Hi all,
SELECT xmlagg(xmlelement(
name actor, xmlattributes(first_name)
)ORDER BY actor_id,',')from actor;

the above code return following result,

[image: Inline image 1]
Question :

i want retrieve result from above XML result like
penelope,nick,jennifer,jhony,,,,,

result of xmlagg is not valid xml.

if you use xmlelement, then you can get valid xml

ostgres=# select * from x;
a
---------------------------------------------------------------
<d><actor first_name="Pavel"/><actor first_name="Tomas"/></d>
(1 row)

postgres=# select unnest(xpath('//actor/@first_name',a)::text[]) from x;
unnest
--------
Pavel
Tomas
(2 rows)

Regards

Pavel

Show quoted text

xpath is their but unable to fix this query.

any help how to get only names from query not xml.

Attachments:

image.pngimage/png; name=image.pngDownload
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#2)
Re: xml

Pavel Stehule <pavel.stehule@gmail.com> writes:

result of xmlagg is not valid xml.

Really? Either that's a bug, or it's declared wrong.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#3)
Re: xml

2015-03-23 15:09 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:

Pavel Stehule <pavel.stehule@gmail.com> writes:

result of xmlagg is not valid xml.

Really? Either that's a bug, or it's declared wrong.

I was not accurate. "<tag /><tag />" is not valid xml document - and xpath
function doens't like it.

postgres=# select xpath('//tag/@x','<tag x="x"/><tag />'::xml);
ERROR: could not parse XML document
DETAIL: line 1: Extra content at the end of the document
<tag x="x"/><tag />
^
CONTEXT: SQL function "xpath" statement 1
postgres=# select xpath('//tag/@x','<x><tag x="x"/><tag /></x>'::xml);
xpath
-------
{x}
(1 row)

postgres=# select '<tag x="x"/><tag />'::xml;
xml
---------------------
<tag x="x"/><tag />
(1 row)

Regards

Pavel

Show quoted text

regards, tom lane