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 1kN1tc-0002Ll-Qg for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 22:45:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kN1tb-0000s5-KL for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 22:45:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN1tb-0000rx-Cw for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 22:45:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN1tZ-000055-Df for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 22:45:22 +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 08SMjITe474456; Mon, 28 Sep 2020 18:45:19 -0400 From: Tom Lane To: Joe Abbate cc: pgsql-general@lists.postgresql.org Subject: Re: DOMAIN/composite TYPE vs. base TYPE In-reply-to: <57a90723-04cd-2036-7184-83e9409f8206@freedomcircle.com> References: <6198aad8-df09-569e-686b-7e32979cd7e4@freedomcircle.com> <409239.1601328317@sss.pgh.pa.us> <57a90723-04cd-2036-7184-83e9409f8206@freedomcircle.com> Comments: In-reply-to Joe Abbate message dated "Mon, 28 Sep 2020 17:58:19 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <474454.1601333118.1@sss.pgh.pa.us> Date: Mon, 28 Sep 2020 18:45:18 -0400 Message-ID: <474455.1601333118@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Joe Abbate writes: > On 28/9/20 17:25, Tom Lane wrote: >> Domain-over-composite might be a slightly simpler answer than your first >> one. It's only available in relatively late-model PG, and I'm not sure >> about its performance relative to your other design, but it is an >> alternative to think about. > "Domain-over-composite" meaning create a TYPE first (DATE, CHAR(1)) and > then a DOMAIN based on that type? Right. regression=# create type t1 as (d date, t char(1)); CREATE TYPE regression=# create domain dt1 as t1 check((value).t in ('a', 'b')); CREATE DOMAIN > (1) How late model are we talking? > The DOMAIN syntax doesn't seem changed from PG 11 to PG 13? Back to 11, looks like. The syntax didn't change, but v10 complains ERROR: "t1" is not a valid base type for a domain >> Note that attaching NOT NULL constraints at the domain level is almost >> never a good idea, because then you find yourself with a semantically >> impossible situation when, say, a column of that type is on the nullable >> side of an outer join. We allow such constraints, but they will be >> nominally violated in cases like that. > NULLs: Tony Hoare's "billion dollars of pain and damage" transported to SQL. I dunno, outer joins are awfully useful. It is true that the SQL committee has stuck too many not-quite-consistent meanings on NULL, but on the other hand, several different kinds of NULL might be worse. regards, tom lane