Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1Guz-00048B-JE for pgsql-sql@arkaria.postgresql.org; Mon, 22 Jul 2013 14:16:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V1Guy-0003mi-W6 for pgsql-sql@arkaria.postgresql.org; Mon, 22 Jul 2013 14:16:53 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1Guy-0003mc-8E for pgsql-sql@postgresql.org; Mon, 22 Jul 2013 14:16:52 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1Guv-00043K-7M for pgsql-sql@postgresql.org; Mon, 22 Jul 2013 14:16:51 +0000 Received: from [192.168.1.45] (gut75-2-82-66-247-92.fbx.proxad.net [82.66.247.92]) by mimolette.dalibo.net (Postfix) with ESMTPSA id C05524502339; Mon, 22 Jul 2013 16:16:46 +0200 (CEST) Message-ID: <51ED3ECB.5020703@dalibo.com> Date: Mon, 22 Jul 2013 16:16:43 +0200 From: Vik Fearing User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: ldrlj1 CC: pgsql-sql@postgresql.org Subject: Re: table constraint on two columns References: <1374501921767-5764645.post@n5.nabble.com> In-Reply-To: <1374501921767-5764645.post@n5.nabble.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 07/22/2013 04:05 PM, ldrlj1 wrote: > Postgres 9.2.4. > > I have two columns, approved and comments. Approved is a boolean with no > default value and comments is a character varying (255) and nullable. > > I am trying to create a constraint that will not allow a row to be entered > if approved is set to false and comments is null. CHECK constraints work on positives, so restate your condition that way. A row is permissible if approved is true or the comments are not null, correct? So... ...add constraint chk_comments (approved or comments is not null)... > This does not work. yada, yada, yada... add constraint "chk_comments' check > (approved = false and comments is not null). The constraint is successfully > added, but does not work as I expected. That's not the same check as what you described. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql