pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: atrigent@ccs.neu.edu
To: 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 10:06:48 -0500
Message-ID: <4F97CCB80200002500047332@gw.wicourts.gov> (raw)
In-Reply-To: <CAM-w4HMCCRD3SOKkdoRO0WHK6Vm5bYp-X_3gvtOxaU592+514g@mail.gmail.com>
References: <E1SMzX4-0004Is-FF@wrigleys.postgresql.org>
	<CAM-w4HMCCRD3SOKkdoRO0WHK6Vm5bYp-X_3gvtOxaU592+514g@mail.gmail.com>

Greg Stark <stark@mit.edu> wrote:
 
> Only IMMUTABLE functions can be used in CHECK constraints.
> It's a feature that expressions including subqueries are
> automatically detected as not being immutable and automatically
> barred.
 
It doesn't look like that to me:
 
test=# create function xxx() returns text volatile language plpgsql
as $$ begin return 'xxx'; end; $$;
CREATE FUNCTION
test=# create table x (id int not null primary key, val text check
(val <> xxx()));
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"x_pkey" for table "x"
CREATE TABLE
test=# insert into x values (1, 'aaa');
INSERT 0 1
test=# insert into x values (2, 'xxx');
ERROR:  new row for relation "x" violates check constraint
"x_val_check"
DETAIL:  Failing row contains (2, xxx).
 
Perhaps you're thinking of function usage in index definitions?

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.
 
Otherwise I agree with your response -- this is clearly *not* a bug.
 
-Kevin



view thread (9+ messages)  latest in thread

Message-ID: <4F97CCB80200002500047332@gw.wicourts.gov>
Permalink:  ../4F97CCB80200002500047332@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4F97CCB80200002500047332@gw.wicourts.gov

 · 

reply

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: 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: <4F97CCB80200002500047332@gw.wicourts.gov>
  References: <E1SMzX4-0004Is-FF@wrigleys.postgresql.org> <CAM-w4HMCCRD3SOKkdoRO0WHK6Vm5bYp-X_3gvtOxaU592+514g@mail.gmail.com> <4F97CCB80200002500047332@gw.wicourts.gov>

* 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