Re: When to use cascading deletes?

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: When to use cascading deletes?
Date: 2009-06-11 11:19:16
Message-ID: h0qp7k$gq9$2@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I use cascading deletes as per business rule.
For example, my customer record has multiple orders and each order can
have multiple shipments and multiple payments.
My business rule is not to erase a customer with orders, but orders
should be erased even if they have shipments or payments.

The business logic behind this was that we want to make it a hassle to
erase a customer. On the other hand, erasing an order that has shipments
or payments is done very regularly, because shipment and payment
records are added before they actually happen (planned shipment and
payments), so order records are erased when the order isn't finalized.
The business rule was to make it less of a hassle.

Sim

David wrote:
> Hi there.
>
> When is a good time to use cascading deletes?
>
> Usually, for safety reasons, I prefer to not ever use cascading
> deletes. But that can lead to some complex code that uses topological
> sorts etc to manually delete records in the right order, when a
> cascading delete is needed.

> I don't know, maybe I have the wrong mindset, and cascading is
> preferable (in terms of object model) in some cases? I'd like to read
> more on this subject (general best practices for what types of
> cascading are appropriate to use when).
>
> Any tips?
>
> Thanks,
>
> David.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marko Kreen 2009-06-11 11:22:49 Re: queries on xmin
Previous Message Sim Zacks 2009-06-11 11:16:56 Re: Array Parameters in EXECUTE