Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iBGCW-0003iF-BD for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2019 10:31:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iBGBW-0004zd-1L for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2019 10:30:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iBGBV-0004zO-Dv for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2019 10:30:41 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iBGBO-0000AN-0B for pgsql-general@postgresql.org; Fri, 20 Sep 2019 10:30:39 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46ZVNS0Tz5z1ptV; Fri, 20 Sep 2019 06:30:31 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46ZVNR6hq7z1ZVV; Fri, 20 Sep 2019 06:30:31 -0400 (EDT) Date: Fri, 20 Sep 2019 06:30:31 -0400 From: stan To: Michael Lewis Cc: pgsql-general@postgresql.org Subject: Re: FW: Re: FW: Re: Shouldn;t this trigger be called? Message-ID: <20190920103031.GA21182@panix.com> References: <50d5b256-74b9-1949-a634-0df37cbfb783@aklaver.com> <20190916010439.GA7478@panix.com> <11b4428d-8740-07f4-a053-37f0bb0cd2fb@aklaver.com> <20190916185333.GB28966@panix.com> <20190916195543.GA16882@panix.com> <4b1da094-8342-6415-e0a4-ce87fd1331ab@aklaver.com> <20190917093126.GA935@panix.com> <699cb705-0609-c830-b6c3-3a4aa9bc2e58@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Sep 19, 2019 at 03:54:40PM -0600, Michael Lewis wrote: > You can also look at citext type to avoid the casting. Oh, that looks really useful I think I will go back and use that type quite a bit. Thanks for pointing it out to me. > > customer_key integer DEFAULT > nextval('customer_key_serial') PRIMARY KEY , > cust_no smallint NOT NULL UNIQUE , > name varchar UNIQUE , > > Why do you have a surrogate primary key generated by a sequence when you > have a natural key of either cust_no or name? Why not just declare the > customer number to be the PK? At the moment, the customer (who is a small startup) really does not have a customer number. It is really a place holder at the moment, with the sequence being the "real" key. For all I know, the customer number may be alphanumeric. in the final implementation. > Where does customer number come from anyway? > Using smallint seems potentially short-sighted on potential future growth, > but changing the type later should be minimal work as long as you don't > have this customer_number denormalized many places, or use it as the FKey > after dropping customer_key surrogate key. Thanks for your suggestion. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin