Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 3549247628D; Mon, 10 Jun 2002 17:00:19 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id D3FCE475C3D; Mon, 10 Jun 2002 16:38:45 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g5AKcKb08544; Mon, 10 Jun 2002 16:38:20 -0400 (EDT) To: terry@greatgulfhomes.com Cc: "'Jan Wieck'" , "'Achilleus Mantzios'" , pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: Re: [SQL] VIEWs and FOREIGN keys In-reply-to: <002801c210af$9088c980$2766f30a@development.greatgulfhomes.com> References: <002801c210af$9088c980$2766f30a@development.greatgulfhomes.com> Comments: In-reply-to terry@greatgulfhomes.com message dated "Mon, 10 Jun 2002 14:49:33 -0400" Date: Mon, 10 Jun 2002 16:38:20 -0400 Message-ID: <8541.1023741500@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200206/300 X-Sequence-Number: 25452 terry@greatgulfhomes.com writes: > I would just like to elaborate, and clarify if my understanding is correct: > The implication of below is that you need a trigger in the foreign key > target table on the DELETE event, so the foreign key table only lets you > delete a row if there are no other tables refering to the key you want to > delete. > Views cannot have triggers, hence cannot have a DELETE trigger, therefore > that is why the view cannot be a foreign key target table. Got it in one. One could perhaps imagine putting triggers on the table(s) that are referenced by the view, but those triggers would have to do very slow and expensive things to enforce the deletion constraint, at least in the interesting cases where the view is a join, aggregation, GROUP BY, etc... regards, tom lane