user defined XML aggregate not working as (i think) it should

From: "Rhys A(dot)D(dot) Stewart" <rhys(dot)stewart(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: user defined XML aggregate not working as (i think) it should
Date: 2012-10-03 22:35:26
Message-ID: CACg0vTkOOtLoEgfbiNr0k_auBUv4M41d7vUf9XS3B6uXrjYCxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greetings!

I have an xml aggregate function that always returns 'ERROR: invalid
XML content'. However an identical function that uses text produces
valid xml with the same inputs.

create schema kml;

CREATE FUNCTION kml.precon(text, text) RETURNS text AS $$ select
$1||$2 $$ LANGUAGE sql;

CREATE FUNCTION kml.precon(xml, xml) RETURNS xml AS $$ select
xmlconcat($1,$2) $$ LANGUAGE sql;

CREATE AGGREGATE kml.documentagg(text) ( SFUNC=kml.precon,
STYPE=text, INITCOND='');

CREATE AGGREGATE kml.documentagg(xml) (SFUNC=kml.precon, STYPE=xml,
INITCOND='');

with one as (
select '<Placemark><name>892033</name><description>MRIL-JULY-2012_RA
265/5-410</description><Point><coordinates>-76.801342826571982,17.98077767785141</coordinates></Point></Placemark>'
k
union
select '<Placemark><name>900527</name><description>MRIL-JULY-2012_RA
265/5-810 </description><Point><coordinates>-76.803804151610237,17.98304310341128</coordinates></Point></Placemark>'
union
select '<Placemark><name>920661</name><description>MRIL-JULY-2012_RA
001/6-310</description><Point><coordinates>-77.886619999671524,18.441619925883373</coordinates></Point></Placemark>'
)

select k from one ; /* returns 3 rows of text. expected*/

select k::xml from one ; /* returns 3 rows of xml. expected*/

select kml.documentagg(k) from one; /* returns one row text */

select kml.documentagg(k)::xml from one; /* returns one row xml */

select kml.documentagg(k::xml) from one ; /* ********** Error
********** ERROR: invalid XML content SQL state: 2200N */

Given that the text agg can be cast to xml without any errors I'm at a
loss as to why the xml agg is failing.

Regards,

Rhys

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2012-10-04 01:25:55 Re: Fwd: pros and cons of two security models
Previous Message Frank Lanitz 2012-10-03 20:22:42 Re: PostgreSQL force create table / ignore constraints?