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 ---------------- - + - 1 + - one + - + - + - + - 2 + - two + - + - + + cursor_to_xml +------------------------------------------------------------ + + + + + + + 1 + + one + + + + + + + + 2 + + two + + + + + + + (1 row)