Re: [HACKERS] CHECK constraints inconsistencies

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rod Taylor <pg(at)rbt(dot)ca>
Cc: Bruno Wolff III <bruno(at)wolff(dot)to>, Michael Glaesemann <grzm(at)myrealbox(dot)com>, pgsql-bugs(at)postgresql(dot)org, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] CHECK constraints inconsistencies
Date: 2004-03-02 03:36:38
Message-ID: 14682.1078198598@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Rod Taylor <pg(at)rbt(dot)ca> writes:
> On Mon, 2004-03-01 at 20:43, Bruno Wolff III wrote:
>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Michael Glaesemann <grzm(at)myrealbox(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2004-03-02 08:15:15 Solved: initdb failed for CVS version
Previous Message Rod Taylor 2004-03-02 02:25:01 Re: CHECK constraints inconsistencies

Browse pgsql-hackers by date

  From Date Subject
Next Message Curt Sampson 2004-03-02 03:59:41 Re: Check Constraints and pg_dump
Previous Message Tom Lane 2004-03-02 03:22:24 Re: Check Constraints and pg_dump