Foreign key
Foreign key
От:
"Paulo Roberto Siqueira" <paulo.siqueira@usa.net>
Дата:
This list have helped me a lot. That's why I'm here again asking for more information. I've read all the documentation, but I need more information on how postgres implements foreign key on version 7.0.2. I know it uses triggers. More information is needed though. I want to know the mechanism, when it will change to real foreign key etc. Thank you all, Paulo Siqueira
Re: [ADMIN] Foreign key
От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:
On Tue, 3 Oct 2000, Paulo Roberto Siqueira wrote: > This list have helped me a lot. That's why I'm here again asking for more > information. > I've read all the documentation, but I need more information on how > postgres implements foreign key on version 7.0.2. I know it uses triggers. > More information is needed though. I want to know the mechanism, when it > will change to real foreign key etc. The mechanics are that a foreign key constraint definition is turned into three constraint triggers (more on this in a second), one on the foreign key table, two on the primary key table. The one on the foreign key table is an after update/insert trigger that checks that the row matches. The two on the primary key table are after delete and update (respectively) and either implement a check to make sure the row isn't referenced (no action/restrict) or implement the referential action (on delete ... on cascade ...) The checks and actions are all implemented in C using SPI by building appropriate queries. Constraint triggers are a little different from normal triggers because there is some additional stuff to handle the relationship between the tables and a deferred trigger queue to handle deferrable constraints. I'm not sure what you mean by real foreign key above, so I'm not sure how to answer the last bit.