Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Flh-0004HV-Gf for pgsql-general@arkaria.postgresql.org; Wed, 20 Jan 2021 15:51:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2Flg-00074S-Dq for pgsql-general@arkaria.postgresql.org; Wed, 20 Jan 2021 15:51:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Flg-00074K-5x for pgsql-general@lists.postgresql.org; Wed, 20 Jan 2021 15:51:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Fle-0002Cg-7Y for pgsql-general@lists.postgresql.org; Wed, 20 Jan 2021 15:51: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 10KFpVS4596024; Wed, 20 Jan 2021 10:51:31 -0500 From: Tom Lane To: "David G. Johnston" cc: Avery Fischer , "pgsql-generallists.postgresql.org" Subject: Re: Cannot create canonicalization function for user-defined range type In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Wed, 20 Jan 2021 07:41:58 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <596022.1611157891.1@sss.pgh.pa.us> Date: Wed, 20 Jan 2021 10:51:31 -0500 Message-ID: <596023.1611157891@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Wed, Jan 20, 2021 at 5:00 AM Avery Fischer wrote: >> ERROR: PL/pgSQL functions cannot return type myrange >> Am I misunderstanding the docs, or are they out-of-date, or is something >> else going on? How can I create a canonicalization function for my range >> type? > Thus one needs to write a C language function if one wishes to implement a > custom range. Yeah, that's the only way at the moment. We've not seen much use-case for writing canonicalization functions in PLs, because of (a) performance and (b) circularity concerns --- the latter meaning that the PL's own infrastructure is likely to expect that it can manipulate scalar values without incurring recursion. These are pretty much the same reasons why a datatype's I/O functions can't be written in a PL. regards, tom lane