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 1kN1A9-0000PA-EC for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 21:58:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kN1A8-0002Ry-8Q for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 21:58:24 +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 1kN1A8-0002Rq-0y for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 21:58:24 +0000 Received: from freedomcircle.com ([208.71.169.155] helo=mail.freedomcircle.com) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kN1A5-0002VA-KO for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 21:58:23 +0000 Received: from [192.168.1.7] (unknown [173.170.129.0]) by mail.freedomcircle.com (Postfix) with ESMTPSA id 5B3CA2A042; Mon, 28 Sep 2020 21:58:20 +0000 (UTC) Subject: Re: DOMAIN/composite TYPE vs. base TYPE To: Tom Lane Cc: pgsql-general@lists.postgresql.org References: <6198aad8-df09-569e-686b-7e32979cd7e4@freedomcircle.com> <409239.1601328317@sss.pgh.pa.us> From: Joe Abbate Message-ID: <57a90723-04cd-2036-7184-83e9409f8206@freedomcircle.com> Date: Mon, 28 Sep 2020 17:58:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <409239.1601328317@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Tom, 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? (1) How late model are we talking? The DOMAIN syntax doesn't seem changed from PG 11 to PG 13? (2) Can a CHECK constraint specify attributes of the composite? > 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. Joe