Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8EEFF9FB5D8 for ; Wed, 28 Feb 2007 06:51:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 13798-10 for ; Wed, 28 Feb 2007 06:51:07 -0400 (AST) X-Greylist: delayed 00:20:08.013753 by SQLgrey-1.7.4 Received: from ns1.officenet.no (ns1.officenet.no [193.212.174.3]) by postgresql.org (Postfix) with ESMTP id DD2109FB652 for ; Wed, 28 Feb 2007 06:51:10 -0400 (AST) Received: from [193.90.138.186] (helo=[10.14.12.130]) by ns1.officenet.no with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.60) (envelope-from ) id 1HMM5H-0006tq-16 for pgsql-sql@postgresql.org; Wed, 28 Feb 2007 11:31:00 +0100 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Conditional NOT NULL constraint Date: Wed, 28 Feb 2007 11:30:47 +0100 User-Agent: KMail/1.9.6 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200702281130.47396.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200702/287 X-Sequence-Number: 27621 Hi all! Is there a simple way to add a "NOT NULL constraint" to a column without us= ing=20 a trigger if another column is not null? Something like this: CREATE TABLE activity( id SERIAL primary key, name varchar not null, created timestamp not null default now(), modified timestamp, created_by integer not null, modified_by integer ); alter table activity alter column modified_by set not null where modified i= s=20 not null; I want a constraint which says: "modified_by not null if modified is not=20 null". I know I could use a trigger for this, but I'm curious if there is a way to= do=20 this with an index. =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager gpg public_key: http://dev.officenet.no/~andreak/public_key.asc =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Karenslyst All=E9 11 | know how to do a thing and to watch | PO. Box 529 Sk=F8yen | somebody else doing it wrong, without | 0214 Oslo | comment. | NORWAY | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+