pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13810: cursor_to_xml ignores tableforest parameter
8+ messages / 4 participants
[nested] [flat]

* BUG #13810: cursor_to_xml ignores tableforest parameter
@ 2015-12-09 14:07 filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: filip@jirsak.org @ 2015-12-09 14:07 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13810
Logged by:          Filip Jirsák
Email address:      filip@jirsak.org
PostgreSQL version: 9.4.5
Operating system:   x86_64-pc-linux-gnu
Description:        

CREATE FUNCTION test_cursor_to_xml() RETURNS xml AS $$
DECLARE
    curs CURSOR FOR SELECT generate_series(1, 5);
BEGIN
  OPEN curs;
  RETURN cursor_to_xml(curs, 10, TRUE, FALSE, '');
END;
$$ LANGUAGE plpgsql;

SELECT test_cursor_to_xml();


This returns XML forrest instead of XML document with single root.


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
@ 2016-08-02 17:48 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Peter Eisentraut @ 2016-08-02 17:48 UTC (permalink / raw)
  To: filip@jirsak.org; pgsql-bugs

On 12/9/15 9:07 AM, filip@jirsak.org wrote:
> CREATE FUNCTION test_cursor_to_xml() RETURNS xml AS $$
> DECLARE
>     curs CURSOR FOR SELECT generate_series(1, 5);
> BEGIN
>   OPEN curs;
>   RETURN cursor_to_xml(curs, 10, TRUE, FALSE, '');
> END;
> $$ LANGUAGE plpgsql;
> 
> SELECT test_cursor_to_xml();
> 
> 
> This returns XML forrest instead of XML document with single root.

You're right, this should have a <table>...</table> around it, like
query_to_xml() does.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-08-03 00:03   ` Thomas Munro <thomas.munro@enterprisedb.com>
  2017-05-04 01:55     ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Thomas Munro @ 2016-08-03 00:03 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs

On Wed, Aug 3, 2016 at 5:48 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
> On 12/9/15 9:07 AM, filip@jirsak.org wrote:
>> CREATE FUNCTION test_cursor_to_xml() RETURNS xml AS $$
>> DECLARE
>>     curs CURSOR FOR SELECT generate_series(1, 5);
>> BEGIN
>>   OPEN curs;
>>   RETURN cursor_to_xml(curs, 10, TRUE, FALSE, '');
>> END;
>> $$ LANGUAGE plpgsql;
>>
>> SELECT test_cursor_to_xml();
>>
>>
>> This returns XML forrest instead of XML document with single root.
>
> You're right, this should have a <table>...</table> around it, like
> query_to_xml() does.

Then it would have to use the cursor name, not a table name, like this, right?

-- 
Thomas Munro
http://www.enterprisedb.com

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

Attachments:

cursor-to-xml.patch (application/octet-stream, 2.8K) download diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 7ed5bcb..a3a4fc6 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -164,6 +164,10 @@ static const char *map_sql_type_to_xmlschema_type(Oid typeoid, int typmod); static void SPI_sql_row_to_xmlelement(uint64 rownum, StringInfo result, char *tablename, bool nulls, bool tableforest, const char *targetns, bool top_level); +static void xmldata_root_element_start(StringInfo result, const char *eltname, + const char *xmlschema, const char *targetns, + bool top_level); +static void xmldata_root_element_end(StringInfo result, const char *eltname); #define NO_XML_SUPPORT() \ ereport(ERROR, \ @@ -2380,9 +2384,17 @@ cursor_to_xml(PG_FUNCTION_ARGS) StringInfoData result; Portal portal; uint64 i; + char *xmltn = NULL; initStringInfo(&result); + if (!tableforest) + { + xmltn = map_sql_identifier_to_xml_name(name, true, false); + xmldata_root_element_start(&result, xmltn, NULL, targetns, true); + appendStringInfoChar(&result, '\n'); + } + SPI_connect(); portal = SPI_cursor_find(name); if (portal == NULL) @@ -2397,6 +2409,9 @@ cursor_to_xml(PG_FUNCTION_ARGS) SPI_finish(); + if (!tableforest) + xmldata_root_element_end(&result, xmltn); + PG_RETURN_XML_P(stringinfo_to_xmltype(&result)); } diff --git a/src/test/regress/expected/xmlmap.out b/src/test/regress/expected/xmlmap.out index b50396f..bbe5d60 100644 --- a/src/test/regress/expected/xmlmap.out +++ b/src/test/regress/expected/xmlmap.out @@ -698,18 +698,21 @@ SELECT cursor_to_xml('xc'::refcursor, 5, false, true, ''); MOVE FIRST IN xc; SELECT cursor_to_xml('xc'::refcursor, 5, true, false, ''); - cursor_to_xml ---------------- - <row> + - <a>1</a> + - <b>one</b> + - </row> + - + - <row> + - <a>2</a> + - <b>two</b> + - </row> + - + + cursor_to_xml +------------------------------------------------------------ + <xc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+ + + + <row> + + <a>1</a> + + <b>one</b> + + </row> + + + + <row> + + <a>2</a> + + <b>two</b> + + </row> + + + + </xc> + (1 row)
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
@ 2017-05-04 01:55     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2017-05-05 03:15       ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2017-05-05 19:01       ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 8+ messages in thread

From: Peter Eisentraut @ 2017-05-04 01:55 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-bugs

On 8/2/16 20:03, Thomas Munro wrote:
> On Wed, Aug 3, 2016 at 5:48 AM, Peter Eisentraut
> <peter.eisentraut@2ndquadrant.com> wrote:
>> On 12/9/15 9:07 AM, filip@jirsak.org wrote:
>>> CREATE FUNCTION test_cursor_to_xml() RETURNS xml AS $$
>>> DECLARE
>>>     curs CURSOR FOR SELECT generate_series(1, 5);
>>> BEGIN
>>>   OPEN curs;
>>>   RETURN cursor_to_xml(curs, 10, TRUE, FALSE, '');
>>> END;
>>> $$ LANGUAGE plpgsql;
>>>
>>> SELECT test_cursor_to_xml();
>>>
>>>
>>> This returns XML forrest instead of XML document with single root.
>>
>> You're right, this should have a <table>...</table> around it, like
>> query_to_xml() does.
> 
> Then it would have to use the cursor name, not a table name, like this, right?

[older thread]

I have applied a fix for this to master.  I'll let the build farm take
it for a spin and then apply it to the backbranches.

(We don't use the cursor name for the element name.  It's documented to
use just "table".)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
  2017-05-04 01:55     ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2017-05-05 03:15       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Peter Eisentraut @ 2017-05-05 03:15 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-bugs

On 5/3/17 21:55, Peter Eisentraut wrote:
> I have applied a fix for this to master.  I'll let the build farm take
> it for a spin and then apply it to the backbranches.

done

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
  2017-05-04 01:55     ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2017-05-05 19:01       ` Tom Lane <tgl@sss.pgh.pa.us>
  2017-05-08 14:26         ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Tom Lane @ 2017-05-05 19:01 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; pgsql-bugs

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>>> You're right, this should have a <table>...</table> around it, like
>>> query_to_xml() does.

> I have applied a fix for this to master.  I'll let the build farm take
> it for a spin and then apply it to the backbranches.

I think this is missing an update for the documentation.  Section 9.14.4
describes the wrapping nodes as being <tablename> --- don't we want that
to match reality a bit better?

			regards, tom lane


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
  2017-05-04 01:55     ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2017-05-05 19:01       ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Tom Lane <tgl@sss.pgh.pa.us>
@ 2017-05-08 14:26         ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2017-05-08 14:30           ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Peter Eisentraut @ 2017-05-08 14:26 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; pgsql-bugs

On 5/5/17 15:01, Tom Lane wrote:
> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>>>> You're right, this should have a <table>...</table> around it, like
>>>> query_to_xml() does.
> 
>> I have applied a fix for this to master.  I'll let the build farm take
>> it for a spin and then apply it to the backbranches.
> 
> I think this is missing an update for the documentation.  Section 9.14.4
> describes the wrapping nodes as being <tablename> --- don't we want that
> to match reality a bit better?

It also says "If no table name is available, that is, when mapping a
query or a cursor, the string `table` is used in the first format, `row`
in the second format.", so I think it's correct and complete.  (Could
have more examples perhaps, but not critical to bug fix backpatch.)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #13810: cursor_to_xml ignores tableforest parameter
  2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
  2016-08-02 17:48 ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-08-03 00:03   ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Thomas Munro <thomas.munro@enterprisedb.com>
  2017-05-04 01:55     ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2017-05-05 19:01       ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Tom Lane <tgl@sss.pgh.pa.us>
  2017-05-08 14:26         ` Re: BUG #13810: cursor_to_xml ignores tableforest parameter Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2017-05-08 14:30           ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2017-05-08 14:30 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; pgsql-bugs

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 5/5/17 15:01, Tom Lane wrote:
>> I think this is missing an update for the documentation.  Section 9.14.4
>> describes the wrapping nodes as being <tablename> --- don't we want that
>> to match reality a bit better?

> It also says "If no table name is available, that is, when mapping a
> query or a cursor, the string `table` is used in the first format, `row`
> in the second format.", so I think it's correct and complete.  (Could
> have more examples perhaps, but not critical to bug fix backpatch.)

OK, fair enough.

			regards, tom lane


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2017-05-08 14:30 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-12-09 14:07 BUG #13810: cursor_to_xml ignores tableforest parameter filip@jirsak.org
2016-08-02 17:48 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-08-03 00:03   ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-05-04 01:55     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-05-05 03:15       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-05-05 19:01       ` Tom Lane <tgl@sss.pgh.pa.us>
2017-05-08 14:26         ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-05-08 14:30           ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox