Re: [SQL] VIEWs and FOREIGN keys - Mailing list pgsql-general

From Tom Lane
Subject Re: [SQL] VIEWs and FOREIGN keys
Date
Msg-id 8541.1023741500@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] VIEWs and FOREIGN keys  (terry@greatgulfhomes.com)
List pgsql-general
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

pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: logging to a file
Next
From: Andrew Sullivan
Date:
Subject: Re: Help with data transfer please