| From: | "Casey T(dot) Deccio" <ctdecci(at)sandia(dot)gov> |
|---|---|
| To: | andrew(at)supernews(dot)com |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: table constraints |
| Date: | 2005-03-01 01:25:56 |
| Message-ID: | 1109640356.32228.53.camel@boomerang.ran.sandia.gov |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Mon, 2005-02-28 at 18:01 -0700, Andrew - Supernews wrote:
> The CHECK is obviously being evaluated prior to the actual insertion
> of
> the record, whereas the logic of your function clearly expects to be
> evaluated after the insertion.
>
I finally came to that conclusion just a few minutes before I got this
email. However, it was your email that made it quite clear why this
was.
> Allowing non-immutable functions in CHECK is probably an error, since
> it
> can lead to tables which can not be dumped+restored (consider in your
> example what happens when the constraint becomes false as a result of
> deleting a row - at that point, a dump and restore of the table will
> fail,
> since the constraint can not be defined after loading the data if it
> is
> violated by that data).
> Using triggers is a more reliable way to do this sort of thing - at
> least
> then it is clear that you are checking the data only at the time of
> modification, whereas CHECK constraints are declarative constraints
> which
> are expected to be true at all times.
>
This is a very good point. I've now implemented the check with a
trigger, and it works very well. Thanks for the input and the logic.
Casey
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kai Hessing | 2005-03-01 09:36:07 | Re: Advanced SELECT |
| Previous Message | Andrew - Supernews | 2005-03-01 01:09:18 | Re: AutoCommit and DDL |