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 1s06Hj-000rIh-1L for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 21:05:38 +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 1s06Hf-002n9t-K9 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 21:05:36 +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 1s06Hf-002n9l-BD for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 21:05:36 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s06Hd-0004Ax-UX for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 21:05:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 43PL5Wu43998497; Thu, 25 Apr 2024 17:05:32 -0400 From: Tom Lane To: Robert Haas cc: Dilip Kumar , PostgreSQL Hackers Subject: Re: Why don't we support external input/output functions for the composite types In-reply-to: References: <3833077.1714020280@sss.pgh.pa.us> <3952020.1714062859@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Thu, 25 Apr 2024 13:12:39 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3998495.1714079132.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 25 Apr 2024 17:05:32 -0400 Message-ID: <3998496.1714079132@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Thu, Apr 25, 2024 at 12:34 PM Tom Lane wrote: >> Uh, no. My point is that if you make a custom output function >> for "type complex (real float8, imaginary float8)", that function >> will probably crash pretty hard if what it's handed is something >> other than two float8s. > I'm not sure I really buy this. Changing the column definitions > amounts to changing the on-disk format, and no data type can survive a > change to the on-disk format without updating the I/O functions to > match. What I'm trying to say is: given that the command "alter type T alter attribute A type foo" exists, users would reasonably expect the system to honor that on its own for any composite type, because that's what it does today. But it can't if T has custom I/O functions, at least not without understanding how to rewrite those functions. >> I think that to the extent that there's a need for custom I/O >> of something like this, it should be handled by bespoke types, >> similar to (say) type point. > I somewhat agree with this. The main disadvantage of that approach is > that you lose the ability to directly refer to the members, which in > some cases would be quite nice. I bet a lot of people would enjoy > being able to write my_point.x and my_point.y instead of my_point[0] > and my_point[1], for example. But maybe the solution to that is not > $SUBJECT. Nope, it isn't IMO. We already added infrastructure to allow arbitrary custom types to define subscripting operations. I think a case could be made to allow them to define field selection, too. > I think it's confusing and counterintuitive that putting parentheses > around a subexpression completely changes the meaning. I don't know of > any other programming language that behaves that way, I take it that you also don't believe that "2 + 3 * 4" should yield different results from "(2 + 3) * 4"? I could get behind offering an alternative notation, eg "a.b->c does the same thing as (a.b).c", if we could find a reasonable notation that doesn't infringe on user operator namespace. I think that might be hard to do though, and I don't think the existing notation is so awful than we should break existing operators to have an alternative. The business with deprecating => operators a few years ago had the excuse that "the standard says so", but we don't have that justification here. regards, tom lane