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 1gQJS4-0003fb-29 for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Nov 2018 21:57:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gQJS2-0000t1-Mx for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Nov 2018 21:57:26 +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 1gQJS2-0000su-GH for pgsql-bugs@lists.postgresql.org; Fri, 23 Nov 2018 21:57:26 +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 1gQJS0-0001FN-8F for pgsql-bugs@lists.postgresql.org; Fri, 23 Nov 2018 21:57:26 +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 wANLvIN8010852; Fri, 23 Nov 2018 16:57:18 -0500 From: Tom Lane To: mark.drake@golden-hind.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15517: JSONB_BUILD_ARRAY and JSON_BUILD_ARRAY omit XML Declaration (if present) from XML colums In-reply-to: <15517-f8fdb2e6b238eed0@postgresql.org> References: <15517-f8fdb2e6b238eed0@postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Thu, 22 Nov 2018 18:40:08 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10850.1543010238.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 23 Nov 2018 16:57:18 -0500 Message-ID: <10851.1543010238@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?q?PG_Bug_reporting_form?=3D writes: > postgres=3D# select x, x::text, JSONB_BUILD_ARRAY(x,x::text) from foo; > x | x | = jsonb_build_array > ----------------+-------------------------------------+-----------------= -------------------------------------------- > XXX | XXX | ["XXX= ", "XXX"] > 123 | 123 | ["123", "123"] > (2 rows) > As can be seen the JSONB_BUILD_ARRAY of x has omitted the declaration. I > would have expected the declaration to be included in the output for col= umn > X. I don't see anything particularly wrong here, at least not with jsonb_build_array(): it's producing a JSON string equivalent to the displayable value of each expression. Now it is fair to wonder why the displayed form of the second XML value is different from what you get from a cast-to-text. The reason seems to be that xml_out() tries to suppress uninteresting XML declarations, while cast-to-text is just a binary coercion that suppresses nothing. I don't personally use XML enough to knowledgeably attack or defend either of those choices ... but I do note that they've been like that for long enough that it seems unlikely we'd consider changing them. (If the whole idea of cast-to-text producing a different result from the datatype output function upsets you, you're not alone, but there's lots of precedent for that too. Type boolean is probably the poster child there.) regards, tom lane