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 1evVyN-0006pa-Ai for pgsql-general@arkaria.postgresql.org; Mon, 12 Mar 2018 22:31:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evVyM-0001Fl-47 for pgsql-general@arkaria.postgresql.org; Mon, 12 Mar 2018 22:31:14 +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 1evVyL-0001Fa-SY for pgsql-general@lists.postgresql.org; Mon, 12 Mar 2018 22:31:13 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evVyI-00029G-31 for pgsql-general@postgresql.org; Mon, 12 Mar 2018 22:31:12 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 206AB216F7; Mon, 12 Mar 2018 18:31:08 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Mon, 12 Mar 2018 18:31:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=q3N25C s0CjvQdcBsaE1X14E34nsh2w7WmNrtAPkNWrU=; b=dBqOyJ1v3+EOG3gQJp6aJS pcgjQfwc7t7RZXD/EuyWjigGy8LmPT/9SjP90nV6Vqjcu+oC1U0qeevzHwW60UhJ CXyliY5RxPmv+7Y1uDDEEOGai74/OcgbGtwW79JA5Vtu2LDo1C+2v7bhZjW1Y/N5 pv1WJvhjOBPjegzK9r+gqX5LN84OZzI4ulop31KIE2U1BEiCvhhjii3p+dntgHnp IZ+CAYATCf4WbytmGLXWxtr+6qmpKAmYg/FfdS6LSjVRWSXZvJ09HK+EYS6qvPTO ESXOsTALsRXYKjnOEpwW0V78PlDu3NpUpZj8QBA8kbw0OJ49nUx+cCGsIzFxIFEA == X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id BFE377E12E; Mon, 12 Mar 2018 18:31:07 -0400 (EDT) Subject: Re: query_to_xml() returns invalid XML when query returns no rows To: Thomas Kellerer , pgsql-general@postgresql.org References: From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: Date: Mon, 12 Mar 2018 18:31:07 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/12/18 08:18, Thomas Kellerer wrote: > 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, ''); -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services