Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 204E41337B92 for ; Sat, 7 May 2011 10:19:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 16050-01-9 for ; Sat, 7 May 2011 13:19:21 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id C4D8B1337D1F for ; Sat, 7 May 2011 10:08:05 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id p47D84f0004074 for ; Sat, 7 May 2011 10:08:04 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id p47CqIvZ063820 for pgsql-sql@postgresql.org; Sat, 7 May 2011 09:52:18 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.sql Subject: Re: check constraint bug? Date: Sat, 07 May 2011 08:52:21 -0400 Organization: albasani.net Lines: 34 Message-ID: References: <20110506060608.12bd24b0@dick.coachhouse> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: news.albasani.net; logging-data="7IrIRuGpzVBvkey3AcnNSMHNIyJ/GWFVF3WfHqFxcGwmMOA5L9Lo7WyjU2Qxb7fsM+2ZeHKZ+rkVHQyoGQ+15q/o2/GaqzJlvSQ/oDnPvrdaPiEONJw3wgJbziTpUpeR"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:4nlMSULcxVGh+S6ngAzLsv7iARA= To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-5 required=5 tests=BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/47 X-Sequence-Number: 35331 Scott Marlowe wrote: > Tarlika Elisabeth Schmitz wrote: >> I specified: >> >> ALTER TABLE h ADD CONSTRAINT val_h_stats >> CHECK (NOT (sex = 'f') AND (stats IS NOT NULL)); >> >> which was translated to: >> >> ALTER TABLE h ADD CONSTRAINT val_h_stats >> CHECK (NOT sex = 'f'::bpchar AND stats IS NOT NULL); > You need another level of parens: > > CHECK (NOT ((sex = 'f') AND (stats IS NOT NULL))); Because NOT has higher precedence than AND. Note that equals (=), IS and NOTNULL have higher precedence than NOT. So the CHECK expression Scott indicated is equivalent to the parenthesis-minimal CHECK ( NOT ( sex = 'f' AND stats IS NOT NULL ) ) or CHECK ( sex != 'f' OR stats IS NULL ) -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg