Re: When to use cascading deletes? - Mailing list pgsql-general

From Sim Zacks
Subject Re: When to use cascading deletes?
Date
Msg-id h0qp7k$gq9$2@news.hub.org
Whole thread Raw
In response to When to use cascading deletes?  (David <wizzardx@gmail.com>)
List 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.
>

pgsql-general by date:

Previous
From: Sim Zacks
Date:
Subject: Re: Array Parameters in EXECUTE
Next
From: Greg Stark
Date:
Subject: Re: When to use cascading deletes?