dbTalk Databases Forums  

Re: [BUGS] [HACKERS] CHECK constraints inconsistencies

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] [HACKERS] CHECK constraints inconsistencies in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] [HACKERS] CHECK constraints inconsistencies - 03-01-2004 , 07:33 PM






Michael Glaesemann <grzm (AT) myrealbox (DOT) com> writes:
Quote:
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.

Of course, a user could easily get into the sort of situation you
describe anyway, just by lying about the volatility labeling of a
user-defined function. But at least we could say it was his fault
then ;-)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: [BUGS] [HACKERS] CHECK constraints inconsistencies - 03-01-2004 , 07:46 PM






On Mon, Mar 01, 2004 at 20:28:02 -0500,
Tom Lane <tgl (AT) sss (DOT) pgh.pa.us> wrote:
Quote:
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
data was entered it will continue to be in the past (barring someone
resetting the system time). This is something someone might actually
check unlike comparing to random numbers.

I think just noting that check constraints are only checked on inserts
and updates and that this means that check constraints using volatile
or stable functions need to be well thought out.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] [HACKERS] CHECK constraints inconsistencies - 03-01-2004 , 09:41 PM



Rod Taylor <pg (AT) rbt (DOT) ca> writes:
Quote:
On Mon, 2004-03-01 at 20:43, Bruno Wolff III wrote:
Tom Lane <tgl (AT) sss (DOT) pgh.pa.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

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.