Re: CHECK constraints inconsistencies - Mailing list pgsql-hackers

From Tom Lane
Subject Re: CHECK constraints inconsistencies
Date
Msg-id 14682.1078198598@sss.pgh.pa.us
Whole thread Raw
In response to Re: CHECK constraints inconsistencies  (Rod Taylor <pg@rbt.ca>)
List pgsql-hackers
Rod Taylor <pg@rbt.ca> writes:
> On Mon, 2004-03-01 at 20:43, Bruno Wolff III wrote:
>> Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> Michael Glaesemann <grzm@myrealbox.com> writes:
>>>> In both cases, the CHECK constraint uses a function that is stable or 
>>>> volatile. It was suggested that functions used in CHECK constraints be 
>>>> restricted to immutable,
>>> 
>>> This seems reasonable to me.  I'm a bit surprised we do not have such a
>>> check already.
>> 
>> There may be times you want to do this. For example you may want a timestamp
>> to be in the past. In this case as long as it was in the past when the

> Agreed that this is useful behaviour, but a trigger is usually a better
> mechanism for confirming such data as you really only want to check it
> when the value is changed.

Yes.  I was just arguing in a different thread that triggers are the
right way to express one-time checks.  A constraint notionally expresses
an always-true condition.  (The SQL spec defines this more formally as a
condition that must hold at the completion of every statement or every
transaction, depending on the "deferrability" property of the
constraint.)  We presently support only constraints that are of a form
that need only be checked at row insert or update time.  It would be
inconsistent with the spec to consider that part of the fundamental
semantics of check constraints, though --- it's just an implementation
restriction.  Someday we might want to remove that restriction.

Requiring CHECK functions to be immutable is consistent with the
existing implementation restriction.  Misusing them in the way Bruno
suggests is a cute trick, but I think we have to consider it to be
gaming the implementation, not a supported way to do things.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Check Constraints and pg_dump
Next
From: Curt Sampson
Date:
Subject: Re: Check Constraints and pg_dump