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 1o1w4k-0000ec-87 for pgsql-general@arkaria.postgresql.org; Thu, 16 Jun 2022 20:26:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o1w4i-0006ZL-J2 for pgsql-general@arkaria.postgresql.org; Thu, 16 Jun 2022 20:26:44 +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 1o1w4i-0006ZC-8u for pgsql-general@lists.postgresql.org; Thu, 16 Jun 2022 20:26:44 +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 1o1w4g-0001Mj-4h for pgsql-general@lists.postgresql.org; Thu, 16 Jun 2022 20:26:43 +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 25GKQdCp978147; Thu, 16 Jun 2022 16:26:39 -0400 From: Tom Lane To: Daniel Popowich cc: pgsql-general@lists.postgresql.org Subject: Re: Operators on ranges with a domain subtype do not implicitly cast operands of the domain's base type In-reply-to: References: Comments: In-reply-to Daniel Popowich message dated "Thu, 16 Jun 2022 15:59:37 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <978145.1655411199.1@sss.pgh.pa.us> Date: Thu, 16 Jun 2022 16:26:39 -0400 Message-ID: <978146.1655411199@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Popowich writes: > -- domain with underlying type of integer (what constraints we might > -- place on the integer values are not germane to the issue so they're > -- left out). > create domain zzzint integer; > -- a range on our domain > create type zzzrange as range (subtype = zzzint); Why is this a good idea? ISTM the subtype of a range type shouldn't really be a domain. The range type depends very fundamentally on the ordering properties of the subtype, so trying to put some abstraction in there seems a bit misguided. Moreover, there are a whole bunch of weird semantics issues that arise if the domain tries to restrict the set of allowed values. For instance, if the domain disallows "3" (maybe it allows only even integers) then what does a range (2,10) really mean? Should we be expected to figure out that it's effectively [4,10)? What pitfalls does that create for, say, multirange operators? You could usefully make a domain over the range type and put some restrictions at that level, perhaps. regards, tom lane