Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 063D9475FDE for ; Fri, 27 Sep 2002 15:56:57 -0400 (EDT) Received: from primus.vsservices.com (unknown [63.66.136.75]) by postgresql.org (Postfix) with ESMTP id 71A31475DB3 for ; Fri, 27 Sep 2002 15:56:56 -0400 (EDT) Received: from prime.vsservices.com (conr-adsl-dhcp-26-247.txucom.net [209.34.26.247]) by primus.vsservices.com (8.12.6/8.12.5) with SMTP id g8RJuv30081148 for ; Fri, 27 Sep 2002 14:56:57 -0500 (CDT) (envelope-from postgres@vsservices.com) Date: Fri, 27 Sep 2002 14:56:52 -0500 From: GB Clark To: pgsql-sql@postgresql.org Subject: Re: Constraint problems Message-Id: <20020927145652.4c82624e.postgres@vsservices.com> In-Reply-To: <20020927112807.D42421-100000@megazone23.bigpanda.com> References: <20020927131547.09ed1af2.postgres@vsservices.com> <20020927112807.D42421-100000@megazone23.bigpanda.com> X-Mailer: Sylpheed version 0.8.2 (GTK+ 1.2.10; i386-portbld-freebsd4.6) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/391 X-Sequence-Number: 9668 On Fri, 27 Sep 2002 11:29:34 -0700 (PDT) Stephan Szabo wrote: > On Fri, 27 Sep 2002, GB Clark wrote: > > > CREATE TABLE sysusers ( > > user_id INTEGER DEFAULT nextval('sysusers_user_id_seq') > > UNIQUE NOT NULL PRIMARY KEY, > > username text NOT NULL UNIQUE, > > password text NOT NULL, > > > > createby text NOT NULL DEFAULT 'syscreate', > > > > status char(1) DEFAULT 'A' CHECK (status in ('A', 'I')), > > comment1 text, > > comment2 text, > > tstamp timestamp DEFAULT CURRENT_TIMESTAMP > > ); > > > > CREATE UNIQUE INDEX username_unique_idx ON sysusers (username); > > > > INSERT INTO sysusers (username, password, createby) VALUES ('syscreate', 'testing', 'syscreate'); > > > > ALTER TABLE sysusers ADD CONSTRAINT createby_test CHECK (createby in (username)); > > This is only going to check the value of username in the current row. > > Why not use a foreign key from createby to username? > Thanks! The FK was just what I was looking for. I had not relized that I could do a current table reference in a FK declaration. Thanks, GB -- GB Clark II | Roaming FreeBSD Admin gclarkii@VSServices.COM | General Geek CTHULU for President - Why choose the lesser of two evils?