X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7B68DD1B536 for ; Thu, 25 Sep 2003 19:10:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 48428-06 for ; Thu, 25 Sep 2003 16:09:41 -0300 (ADT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id C2FF0D1B537 for ; Thu, 25 Sep 2003 16:09:38 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 1A2bUg-0002JP-0U; Thu, 25 Sep 2003 20:09:39 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id C499316D57; Thu, 25 Sep 2003 20:09:36 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 13EF516BDC; Thu, 25 Sep 2003 20:09:36 +0100 (BST) From: Richard Huxton To: Larry Rosenman , pgsql-sql@postgresql.org Subject: Re: weird(to me) request Date: Thu, 25 Sep 2003 20:09:35 +0100 User-Agent: KMail/1.5 References: <294260000.1064515888@lerlaptop-red.iadfw.net> In-Reply-To: <294260000.1064515888@lerlaptop-red.iadfw.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200309252009.35449.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/314 X-Sequence-Number: 15292 On Thursday 25 September 2003 19:51, Larry Rosenman wrote: > I have the following rows (in addition to others): > > acct_num text, > master_acct_num text, > > > These are in the same table. > > What I want to enforce is that if the master_acct_num field is NOT NULL (it > can be NULL, and > that's fine), that the value appears in some row as acct_num. acct_num has > a unique index on it, so that's fine. > > I'm not sure how to do this.... ALTER TABLE my_table ADD CONSTRAINT my_self_fk FOREIGN KEY (master_acct_num) REFERENCES my_table (acct_num); It's really just a foreign-key to yourself -- Richard Huxton Archonet Ltd