Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNmJm-0002Gw-Uu for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Oct 2019 23:14: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 1iNmJk-0003RH-JN for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Oct 2019 23:14:56 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNmJk-0003RA-0P for pgsql-bugs@lists.postgresql.org; Thu, 24 Oct 2019 23:14:56 +0000 Received: from anastigmatix.net ([68.171.219.55]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNmJh-0006PD-Es for pgsql-bugs@lists.postgresql.org; Thu, 24 Oct 2019 23:14:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=w+J5FzELQ7/r4b20I14rg2r4yyZfKnM+s/XHS3kG4Qg=; b=QGNfQT+ql6VjUtYFm49nTjaN/6 DrDFMInemrbyfaZJf/znHqIkS6GkZ5HLVeruH5JCw2ixLanYMJrLFyazWtB56FJh98Nu8T9MQAPMV JfBloX+WxZn4PubliencO3RTBMlB4TKvl+aBWqKIn1mym/VlFEudPvS/+KMvrN/RRmoDsbr4/rf30 wqRiffXTQwRpgCGwlXPx/k9WhXiZwXGkIwCLPjk1zhUBj0L8ySmiikO3d0HsRHGe3bBbK8hQqs3Gw G5DB9ncfVBIT9HKK3GplUWj/3jaGFlv2bp8+L9/x7JVdkBx9R+XJU7IbP9yYClzBCQ8wT8TM2ZrTh 25hbDkgg==; Received: from [184.19.31.139] (port=40335) by bay.acenet.us with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iNmJd-003SOS-EN; Thu, 24 Oct 2019 19:14:50 -0400 Subject: Re: BUG #16046: xpath returns CDATA tag along with the value in postgres 12 To: Tom Lane , mostafa_bit0108@hotmail.com References: <16046-a04d0611e7a0c03a@postgresql.org> <10621.1571953091@sss.pgh.pa.us> Cc: pgsql-bugs@lists.postgresql.org, Markus Winand , Pavel Stehule From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5DB23068.3080601@anastigmatix.net> Date: Thu, 24 Oct 2019 19:14:48 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <10621.1571953091@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-94.5 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/24/19 17:38, Tom Lane wrote: >> Query: SELECT unnest(xpath('//cname/aname/text()',''::xml)) >> >> Output - pg11: select 5 >> >> Output - pg12: > > ... What's not entirely clear to me is whether it's an intentional > effect, or a bug. Authors, any comments? Hmm. I would say the pg12 behavior is "not wrong". But it's unexpected. xpath's return type is xml (well, array of), so the result must have a form that can escape any characters mistakable for markup. In this example, there aren't any, but once tweaked so there are: SELECT unnest(xpath('//cname/aname/text()', ']]>'::xml)); pg12: ]]> the necessity is clear. The other valid option would be to return, not CDATA, but a regular text node, which would look like straight text if there were no special characters in it, and would otherwise have every such character individually escaped. That's what I get from pg11: SELECT unnest(xpath('//cname/aname/text()', ']]>'::xml)); pg11: select 5 & 6 <yahoo!> So what pg11 is doing is also "not wrong" (in this respect, anyway). And looks "more natural", in the case where the value has no characters that need escaping. Which may or may not be a good thing. Perhaps it could lead the unwary in some cases to think such a query is giving a directly usable text string back, which will be harmless until the one time a value with escaping comes back. (The no-surprises way to get back a directly usable text string, if that's what's wanted, would be with XMLTABLE and an output column of text type.) Oddly, what pg12 is doing seems to be influenced by the form of escaping used in the input: SELECT unnest(xpath('//cname/aname/text()', ']]>'::xml)); unnest ----------------------------------- ]]> SELECT unnest(xpath('//cname/aname/text()', 'select 5 & 6 <yahoo!>'::xml)); unnest --------------------------------- select 5 & 6 <yahoo!> Either form of result is correct, and having it respect the form that was used in the input might even be delightfully smart. I haven't looked in the code just now to see if it is intentionally being delightfully smart, or more simplistic-and-lucky. Regards, -Chap