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 1hHUOR-00020V-Og for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Apr 2019 14:21:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hHUOP-0003Hm-9j for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Apr 2019 14:21:29 +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 1hHUOP-0003Gr-0j for pgsql-bugs@lists.postgresql.org; Fri, 19 Apr 2019 14:21:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHUOM-0007AX-1E for pgsql-bugs@lists.postgresql.org; Fri, 19 Apr 2019 14:21:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x3JELNRG008719; Fri, 19 Apr 2019 10:21:23 -0400 From: Tom Lane To: "Voillequin, Jean-Marc" cc: pgsql-bugs@lists.postgresql.org Subject: Re: xpath insert unexpected newlines In-reply-to: <1EC8157EB499BF459A516ADCF135ADCE3A23A9CA@LON-WGMSX712.ad.moodys.net> References: <1EC8157EB499BF459A516ADCF135ADCE3A23A9CA@LON-WGMSX712.ad.moodys.net> Comments: In-reply-to "Voillequin, Jean-Marc" message dated "Fri, 19 Apr 2019 13:04:37 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8717.1555683683.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 19 Apr 2019 10:21:23 -0400 Message-ID: <8718.1555683683@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk [ redirecting to pgsql-bugs ] "Voillequin, Jean-Marc" writes: > It seems that xpath function add unexpected newlines in the xml elements= it returns as array: > postgres=3D> select ((xpath('/*',xml('')))[1])= ::text; > xpath > --------- > + > + > + > + > > (1 row) > A workaround is to have at least one element with a value: > postgres=3D> select ((xpath('/*',xml('one value= ')))[1])::text; > xpath > ------------------------------------ > one value > (1 row) Wow, that's bizarre. It seems that this behavior is down to xmlNodeDump, which is what we use to produce xpath's output. I'm not sure why it chooses to pretty-print one case and not the other, but I'd be inclined to say that for PG's purposes we don't want any pretty-printing. I tried this: diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index dae7d58..48b8034 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -3857,7 +3857,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur, PgXmlErrorConte= xt *xmlerrcxt) nodefree =3D (cur_copy->type =3D=3D XML_DOCUMENT_NODE) ? (void (*) (xmlNodePtr)) xmlFreeDoc : xmlFreeNode; = - bytes =3D xmlNodeDump(buf, NULL, cur_copy, 0, 1); + bytes =3D xmlNodeDump(buf, NULL, cur_copy, 0, 0); if (bytes =3D=3D -1 || xmlerrcxt->err_occurred) xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY, "could not dump node"); and that makes the discrepancy go away (both results are printed without any added whitespace). There is one change in the regression test outputs, which is an xpath query that's been affected by this very same issue: SELECT xpath('//loc:piece', 'number one', A= RRAY[ARRAY['loc', 'http://127.0.0.1']]); - xpath = = --------------------------------------------------------------------------= ------------- - {"+ - number one = + - = + - ",""} + = xpath = = +-------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------- + {"number one",""} (1 row) Thoughts? regards, tom lane