Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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

pgsql-hackers by date

Next:From: Curt SampsonDate: 2004-03-02 03:59:41
Subject: Re: Check Constraints and pg_dump
Previous:From: Tom LaneDate: 2004-03-02 03:22:24
Subject: Re: Check Constraints and pg_dump

pgsql-bugs by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group