Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evpUk-00011m-Tb for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 19:21:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evpUj-00063q-8a for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 19:21:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evpUj-00063g-0P for pgsql-general@lists.postgresql.org; Tue, 13 Mar 2018 19:21:57 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1evpUg-0004EW-T9 for pgsql-general@postgresql.org; Tue, 13 Mar 2018 19:21:56 +0000 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1evpSc-0003hi-8V for pgsql-general@postgresql.org; Tue, 13 Mar 2018 20:19:46 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Kellerer Subject: Re: query_to_xml() returns invalid XML when query returns no rows Date: Tue, 13 Mar 2018 20:21:47 +0100 Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@blaine.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: Content-Language: de-DE X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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