Re: query_to_xml() returns invalid XML when query returns no rows

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: query_to_xml() returns invalid XML when query returns no rows
Date: 2018-03-13 19:21:47
Message-ID: p8988c$ddt$1@blaine.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ryan Murphy 2018-03-13 20:05:46 Re: Is there a way to create a functional index that tables tableoid column as an arg?
Previous Message Melvin Davidson 2018-03-13 17:47:30 Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format for cloning schemas