Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f3RCq9381246 for ; Fri, 27 Apr 2001 08:52:09 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from linux.scd.net ([209.150.198.180]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3QFDH396572 for ; Thu, 26 Apr 2001 11:13:18 -0400 (EDT) (envelope-from peter@schoenster.com) Received: from home ([209.150.198.179]) by linux.scd.net (8.9.3/8.9.3) with ESMTP id IAA00418 for ; Thu, 26 Apr 2001 08:05:43 -0600 From: "Peter J. Schoenster" Organization: Schoenster To: pgsql-sql@postgresql.org Date: Thu, 26 Apr 2001 09:58:59 -0600 Subject: Re: must I create the function check_primary_key ? Reply-to: peter@schoenster.com Message-ID: <3AE7F163.15642.11DD19@localhost> References: <3AE7463E.27747.CD77E8D@localhost> In-reply-to: X-mailer: Pegasus Mail for Win32 (v3.12c) X-Archive-Number: 200104/421 X-Sequence-Number: 2783 > On Wed, 25 Apr 2001, Peter J. Schoenster wrote: > > > I want to use this referential integrity etc. that I've never used ..snip.. > > CREATE TRIGGER employer_id_exists > > BEFORE INSERT OR UPDATE ON company_profile FOR EACH > > ROW > > EXECUTE PROCEDURE check_primary_key('employer_id', > > 'employer_profile', 'employer_id'); Stephan Szabo enlightened me as such: > You probably just want to use a REFERENCES constraint > employer_id int4 REFERENCES employer_profile(employer_id) > > You'll need to have a primary key or unique constraint > on employer_profile(employer_id). The references constraint > will also prevent you from deleting a employer_id > row that is being referenced. Banging my head on the table ... yes ... I never set the constraint on employer_id in employer_profile. I should have been more patient in reading the error message returned by psql. Thanks for the help. Your suggestion worked as expected. Peter All idioms must be learned. Good idioms only need to be learned once. --Alan Cooper