X-Original-To: pgsql-sql@postgresql.org Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id E6FF64758C9 for ; Sat, 15 Mar 2003 11:15:32 -0500 (EST) Received: (qmail 17525 invoked by uid 500); 15 Mar 2003 16:29:54 -0000 Date: Sat, 15 Mar 2003 10:29:54 -0600 From: Bruno Wolff III To: cliff@cliffmeyers.com Cc: pgsql-sql@postgresql.org Subject: Re: help with table constraint / check Message-ID: <20030315162954.GA17488@wolff.to> Mail-Followup-To: cliff@cliffmeyers.com, pgsql-sql@postgresql.org References: <20030315073820.3084.h016.c001.wm@mail.cliffmeyers.com.criticalpath.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030315073820.3084.h016.c001.wm@mail.cliffmeyers.com.criticalpath.net> User-Agent: Mutt/1.3.25i X-Archive-Number: 200303/375 X-Sequence-Number: 12414 On Sat, Mar 15, 2003 at 07:38:20 -0800, cliff@cliffmeyers.com wrote: > > What I want to do is set up a constraint / check so that when a record is added, > it takes the parent_id being passed in the INSERT statement, looks at the record > whose fs_id equals the parent_id, and makes sure that the fs_type for that record > is 'dir' and not 'file'. > > Can I do this with standard constraints or do I need to use some PL/pgSQL > features? Anyone have a few hints? Thanks! One way to do this is to add a column with the parent's file system type (constrained to be 'dir') and then make the foreign key to the parent use both the parent ID and the file system type.