From: | Benjamin Jury <benjamin(dot)jury(at)mpuk(dot)com> |
---|---|
To: | "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org> |
Subject: | FW: Foreign keys |
Date: | 2003-06-26 11:58:59 |
Message-ID: | 24DC688F52AAD611B60900096BB0B440015D82BA@chapar.mpuk.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> I have foreign keys set up so that if, for example, a record
> in customer
> is deleted, the corresponding records in the customer_addresses table
> are also removed. However, I can't find a way of ensuring
> records in the
> address table are deleted too, given that lots of different
> tables will
> reference address.id.
>
> What I'd like is for records in the address table to be automatically
> deleted at the end of each transaction if nothing references them any
> more. Is there any way to achieve this?
You could set up a function which returns how many references a specific
address has (or even better simply if it has any other references). Then
using a trigger or another function to delete customers, suppliers etc could
use the first function to find out if it can delete the original address.
Ps: Must remember to reply to list not just the original poster! Doh!
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2003-06-26 12:03:22 | Re: Foreign keys |
Previous Message | Bruno Wolff III | 2003-06-26 11:55:16 | Re: Foreign keys |