X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A240F32A040 for ; Tue, 28 Sep 2004 15:14:50 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47640-09 for ; Tue, 28 Sep 2004 14:14:45 +0000 (GMT) Received: from bugs.unl.edu.ar (bugs.unl.edu.ar [168.96.132.208]) by svr1.postgresql.org (Postfix) with ESMTP id 01D0032A048 for ; Tue, 28 Sep 2004 15:14:44 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by bugs.unl.edu.ar (Postfix) with ESMTP id 53EC112355; Tue, 28 Sep 2004 11:12:06 -0300 (ART) Received: from bugs.unl.edu.ar ([127.0.0.1]) by localhost (bugs [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 31204-05; Tue, 28 Sep 2004 11:12:05 -0300 (ART) Received: from localhost (localhost [127.0.0.1]) by bugs.unl.edu.ar (Postfix) with ESMTP id E5A1611E15; Tue, 28 Sep 2004 11:12:04 -0300 (ART) From: Martin Marques To: mailreg@numerixtechnology.de Subject: Re: CHECK col A not NULL if col B='x' Date: Tue, 28 Sep 2004 11:12:02 -0300 User-Agent: KMail/1.6.2 Cc: pgsql-sql References: <41596EDA.4030909@numerixtechnology.de> In-Reply-To: <41596EDA.4030909@numerixtechnology.de> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200409281112.02986.martin@bugs.unl.edu.ar> X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at bugs.unl.edu.ar X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/244 X-Sequence-Number: 19090 El Mar 28 Sep 2004 11:02, T E Schmitz escribi=F3: > Hello, > > Is it possible to set up a table CHECK, which ensures that column A is > NOT NULL if column B =3D 'x' ? CONSTRAINT constraint_name ] CHECK (expression)=20 CHECK (expression) The CHECK clause specifies an expression producing a Boolean result which = new=20 or updated rows must satisfy for an insert or update operation to succeed. = A=20 check constraint specified as a column constraint should reference that=20 column's value only, while an expression appearing in a table constraint ma= y=20 reference multiple columns.=20 So I would say that it should be: CONSTRAINT somename CHECK (B <> 'x' OR A IS NOT NULL) (use a logical table to build the correct logical expression) --=20 11:05:01 up 16 days, 1:23, 4 users, load average: 1.26, 0.70, 1.04 ----------------------------------------------------------------- Mart=EDn Marqu=E9s | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral -----------------------------------------------------------------