Re: query_to_xml() returns invalid XML when query returns no rows - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: query_to_xml() returns invalid XML when query returns no rows
Date
Msg-id p8988c$ddt$1@blaine.gmane.org
Whole thread Raw
In response to Re: query_to_xml() returns invalid XML when query returns no rows  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Responses Re: query_to_xml() returns invalid XML when query returns no rows  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-general
Peter Eisentraut schrieb am 12.03.2018 um 23:31:
>> 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 because the
>> "empty" document is an invalid XML:
> 
> That's because you have the tableforest argument set to true.  If you
> want a proper XML document, then you should write
> 
>      select query_to_xml('select 42 where false', false, false, '');
> 

Hmm, that indeed works.
I didn't want the extra level introduced by the <table> tag, that's why I used tableforest = true.
But that's easier to deal with than the check for an invalid document

I still think it's incorrect to return an empty (=invalid) XML instead of a NULL value though.

Regards
Thomas
  




pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format forcloning schemas
Next
From: Ryan Murphy
Date:
Subject: Re: Is there a way to create a functional index that tables tableoidcolumn as an arg?