query_to_xml() returns invalid XML when query returns no rows

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема query_to_xml() returns invalid XML when query returns no rows
Дата
Msg-id p85r3j$qtb$1@blaine.gmane.org
обсуждение исходный текст
Ответы Re: query_to_xml() returns invalid XML when query returns no rows
Список pgsql-general
I am not sure if this qualifies as a bug: 

query_to_xml() returns an empty XML document when the query returns no rows, e.g:

   select query_to_xml('select 42 where false', false, true, '');

The problem with this is, that if the resulting XML is then fed into e.g. the xpath() function, that function fails
becausethe "empty" document is an invalid XML:
 

So the following query:

    select xpath('/row/col/text()', query_to_xml('select 42 as col where false', false, true, ''));

fails with "ERROR:  could not parse XML document"

I would have expected query_to_xml() to return NULL if the query returns no rows, rather than an invalid XML document.

Note that IS DOCUMENT is false for the empty XML returned, so it can be trapped in a query. 
But if query_to_xml() is nested somehow (like the above) this is really complicated to apply and I find it a bit
surprisingthat query_to_xml() returns invalid XML at all
 

Tested with 10.2 on Windows 10

Thomas






В списке pgsql-general по дате отправления:

Предыдущее
От: lin
Дата:
Сообщение: can someone send a design document of "parallel work" to me?
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: can someone send a design document of "parallel work" to me?