Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tAaJq-00GZM1-Hh for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 19:43:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tAaJn-00HYw7-TX for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 19:43:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tAaJn-00HYuM-Gf for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 19:43:24 +0000 Received: from udcm-wwu4.uni-muenster.de ([128.176.118.31]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tAaJk-001Phm-47 for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 19:43:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uni-muenster.de; i=@uni-muenster.de; q=dns/txt; s=uniout; t=1731354202; x=1762890202; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=b8dCdFkvb0ZVzBzxi1bgX2nE3OOqHbG13pu0+mUJ2Gk=; b=raWRep32axSKms2KV5B6zFlg8pa0g4qJvEkPb/kJtN6abjzlL2nAW17N 3e7MCu5jdIEvMQ1AY+X99y7UMWKMt94zGcyNGPIVN3ZtlMgyWxN0JxDKB oXWdZM48L1nwDMmQnslEMuPTXO4cy7zQst4wCUupIC7MpV5TNqg9wQwDI YNxqQbyfEWExYVbYwSqZ8MoLDg+geuO4cHS4rvspksM3SJGAUYodBUBwx 0sEampMu9aPt69zvLQrazuWff8GyQy7IreSWbDyFE2rDSAQbDRyBUg8MZ qbIdW/ucxJEHyvEMuo1ItYi1bGxElqSONwuzpMWJV+xG7xJZBWyRoFuaN g==; X-CSE-ConnectionGUID: IDbjaqB7QoK3TvYh5MKYJg== X-CSE-MsgGUID: 397zDJ2VQfeF3bDBAJ2r/Q== X-IronPort-AV: E=Sophos;i="6.12,146,1728943200"; d="scan'208";a="12164497" Received: from secmail.uni-muenster.de ([128.176.118.4]) by udcm-relay4.uni-muenster.de with ESMTP; 11 Nov 2024 20:43:21 +0100 Received: from [192.168.178.27] (dynamic-002-243-228-167.2.243.pool.telefonica.de [2.243.228.167]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id C0AFB20ADF05; Mon, 11 Nov 2024 20:43:19 +0100 (CET) Message-ID: <800e2b29-7cf9-42e0-9d95-12b3007d2f7a@uni-muenster.de> Date: Mon, 11 Nov 2024 20:43:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PoC] XMLCast (SQL/XML X025) To: Robert Haas Cc: pgsql-hackers@lists.postgresql.org, Vik Fearing References: <7b99d466-985f-4d27-8c93-9b98c6945ebb@uni-muenster.de> <11f75849-0f10-40d3-bdfe-5ee81c8a0254@uni-muenster.de> <66bf6e05-61d6-4fec-859c-fcfd726bbed6@uni-muenster.de> <7ef2eaf8-6d60-485c-84a6-1f15421e7cb6@uni-muenster.de> Content-Language: en-US From: Jim Jones In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Robert Thanks for taking a look at it. On 11.11.24 19:15, Robert Haas wrote: > Hmm, this patch has gotten no responses for 4 months. That's kind of > unfortunate. Sadly, there's not a whole lot that I can do to better > the situation, because I know very little either about XML-related > standards or about how people make use of XML in practice. It's not > that much code, so if it does a useful thing that we actually want, we > can probably figure out how to verify that the code is correct, or fix > it. But I don't know whether it's a useful thing that we actually > want. Syntactically, XMLCAST() looks a lot like CAST(), so one might > ask whether the things that it does can already be accomplished using > CAST(); or whether, perhaps, we have some other existing method for > performing such conversions. It indeed has a huge overlap with CAST(), except for a few handy SQL <-> XML mappings, such as SELECT xmlcast('foo & <"bar">'::xml AS text);     xmlcast     ---------------  foo & <"bar"> (1 row) -- SELECT   xmlcast('2024-05-29 12:04:10.703585+02'::timestamp without time zone AS xml),   xmlcast('2024-05-29T12:04:10.703585'::xml AS timestamp without time zone);             xmlcast           |          xmlcast            ----------------------------+----------------------------  2024-05-29T12:04:10.703585 | 2024-05-29 12:04:10.703585 (1 row) -- SELECT   xmlcast('P1Y2M3DT4H5M6S'::xml AS interval),   xmlcast('1 year 2 mons 3 days 4 hours 5 minutes 6 seconds'::interval AS xml);               xmlcast            |    xmlcast      -------------------------------+----------------  1 year 2 mons 3 days 04:05:06 | P1Y2M3DT4H5M6S (1 row) -- SELECT CAST('42'::xml AS int); ERROR:  cannot cast type xml to integer LINE 1: SELECT CAST('42'::xml AS int);                ^ -- SELECT XMLCAST('42'::xml AS int);  xmlcast ---------       42 (1 row) > The only thing I found during a quick perusal of the documentation was > XMLTABLE(), which seems a bit baroque if you just want to convert one > value. Is this intended to plug that gap? Is there any other current > way of doing it? > > Do we need to ensure some kind of consistency between XMLTABLE() and > XMLCAST() in terms of how they behave? I haven't considered any compatibility to XMLTABLE(), as it has a different spec (X300-X305), but I can take a look at it! To implement this function I just followed the SQL/XML spec "ISO/IEC IWD 9075-14" - and from time to time I also took a look on how other databases implemented it.[1] > The documentation at > https://www.postgresql.org/docs/current/xml-limits-conformance.html#FUNCTIONS-XML-LIMITS-CASTS > says that "When PostgreSQL maps SQL data values to XML (as in > xmlelement), or XML to SQL (as in the output columns of xmltable), > except for a few cases treated specially, PostgreSQL simply assumes > that the XML data type's XPath 1.0 string form will be valid as the > text-input form of the SQL datatype, and conversely." Unfortunately, > it does not specify what those cases treated specially are, and the > commit that added that documentation text is not the one that added > the underlying code, so I don't actually know where that code is, but > one would expect this function to conform to that general rule. I agree. It would be nice to know which cases those are. However, invalid inputs should normally return an error, e.g. SELECT xmlcast('foo&bar'::xml AS text); ERROR:  invalid XML content LINE 1: SELECT xmlcast('foo&bar'::xml AS text);                        ^ DETAIL:  line 1: EntityRef: expecting ';' foo&bar        ^ -- SELECT xmlcast('foo'::xml AS date); ERROR:  invalid input syntax for type date: "foo" -- .. but perhaps the text means something else? Thanks! Best, Jim 1 - https://dbfiddle.uk/ZSpsyIal