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 CE3AF32A05A for ; Tue, 28 Sep 2004 15:15:09 +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 50100-03 for ; Tue, 28 Sep 2004 14:15:04 +0000 (GMT) Received: from dyatel.antar.bryansk.ru (unknown [195.239.214.85]) by svr1.postgresql.org (Postfix) with ESMTP id ADF3A32A028 for ; Tue, 28 Sep 2004 15:15:07 +0100 (BST) Received: from fduch by dyatel.antar.bryansk.ru with local (Exim 4.42 (FreeBSD)) id 1CCIky-000CxN-Lj; Tue, 28 Sep 2004 18:15:04 +0400 Date: Tue, 28 Sep 2004 18:15:04 +0400 From: "Alexander M. Pravking" To: T E Schmitz Cc: pgsql-sql Subject: Re: CHECK col A not NULL if col B='x' Message-ID: <20040928141504.GA17595@dyatel.antar.bryansk.ru> References: <41596EDA.4030909@numerixtechnology.de> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <41596EDA.4030909@numerixtechnology.de> User-Agent: Mutt/1.4.2.1i 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/245 X-Sequence-Number: 19091 On Tue, Sep 28, 2004 at 03:02:02PM +0100, T E Schmitz wrote: > Hello, > > Is it possible to set up a table CHECK, which ensures that column A is > NOT NULL if column B = 'x' ? Sure. fduch@~=# CREATE TABLE test ( fduch@~(# a integer check (case when b = 'x' then a is not null else true end), fduch@~(# b text); CREATE TABLE fduch@~=# INSERT INTO test VALUES (null, '123'); INSERT 107538 1 fduch@~=# INSERT INTO test VALUES (null, 'x'); ERROR: new row for relation "test" violates check constraint "test_a" fduch@~=# INSERT INTO test VALUES (1, 'x'); INSERT 107539 1 -- Fduch M. Pravking