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 1iBGmT-0004vo-QQ for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2019 11:08:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iBGmS-0004YT-5C for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2019 11:08:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iBGmR-0004YA-RH for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2019 11:08:51 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iBGmO-0004iF-Im for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2019 11:08:51 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46ZWDZ36V4z1rNr; Fri, 20 Sep 2019 07:08:46 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46ZWDZ2Lfvz1ZVV; Fri, 20 Sep 2019 07:08:46 -0400 (EDT) Date: Fri, 20 Sep 2019 07:08:46 -0400 From: stan To: Morris de Oryx Cc: pgsql-general@lists.postgresql.org Subject: Re: FW: Re: FW: Re: Shouldn;t this trigger be called? Message-ID: <20190920110846.GB12885@panix.com> References: <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> <20190920103031.GA21182@panix.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 Fri, Sep 20, 2019 at 08:52:00PM +1000, Morris de Oryx wrote: > I see that you've already been pointed at citext, but I don't think a CHECK > constraint has been mentioned. In case it hasn't, what about something like > this? > > ADD CONSTRAINT check_activity_status > CHECK (activity_status = 'ACTIVE' OR activity_status = 'INACTIVE'); > > I'm kind of allergic to ENUM...maybe that's just me. But since you're > considering it, maybe it's the perfect time to consider all of your > options. Such as a linked lookup table of defined allowed values (feels > silly with two values), a domain (not entirely fit to purpose), or the > CHECK constraint above. And, yeah, if it's only ever ACTIVE or INACTIVE, > I'd normally make a Boolean named something like active, as Adrian Klaver > mentioned. That's easy to reason about, and it makes it unambiguous that > there are two and only two possible states.. Thanks you. I actually have a number of these cases, and I sullied the simplest one, which just has 2 values. I guess my "C: background is showing here. I do have some similar situations where I did use a table of allowed conditions. I am thinking citext may be the best solution here. I am having an issue getting it to work, though. I don't have to do anything special to enable this type, do I? What I am really trying to do is "human proof" this input :-) -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin