From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: atrigent@ccs.neu.edu
Cc: Greg Stark <stark@mit.edu>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6612: Functions can be called inside CHECK statements
Date: Wed, 25 Apr 2012 11:46:01 -0400
Message-ID: <6552.1335368761@sss.pgh.pa.us> (raw)
In-Reply-To: <4F97CCB80200002500047332@gw.wicourts.gov>
References: <E1SMzX4-0004Is-FF@wrigleys.postgresql.org>
<CAM-w4HMCCRD3SOKkdoRO0WHK6Vm5bYp-X_3gvtOxaU592+514g@mail.gmail.com>
<4F97CCB80200002500047332@gw.wicourts.gov>
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> Greg Stark <stark@mit.edu> wrote:
>> Only IMMUTABLE functions can be used in CHECK constraints.
> It doesn't look like that to me:
No, we have never enforced that. IIRC the idea has been discussed,
but we thought that adding the restriction would break too many
existing applications.
> A CHECK constraint using a volatile function is potentially valid
> and useful, IMO. Think about a column which is supposed to record
> the moment of an event which has occurred. It could make sense to
> ensure that the timestamptz value is < now(); On the other hand, an
> index entry based on now() is clearly a problem.
This example is actually stable not volatile, but if for some reason
you wanted to use clock_timestamp() then it would be volatile.
Probably a more interesting question is whether it'd ever be sane to use
a function with side-effects in a check constraint. I find it hard to
visualize a case where it wouldn't be saner to put the actions in a
trigger, but that doesn't mean someone else might not wish to do it.
In practice, the times when check constraints are checked are
predictable enough that you should be able to get away with abusing
the system like that, if you wished.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, Kevin.Grittner@wicourts.gov, atrigent@ccs.neu.edu, stark@mit.edu
Subject: Re: BUG #6612: Functions can be called inside CHECK statements
In-Reply-To: <6552.1335368761@sss.pgh.pa.us>
References: <E1SMzX4-0004Is-FF@wrigleys.postgresql.org> <CAM-w4HMCCRD3SOKkdoRO0WHK6Vm5bYp-X_3gvtOxaU592+514g@mail.gmail.com> <4F97CCB80200002500047332@gw.wicourts.gov> <6552.1335368761@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox