Re: BUG #6612: Functions can be called inside CHECK statements

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: BUG #6612: Functions can be called inside CHECK statements
Дата
Msg-id 4F97CCB80200002500047332@gw.wicourts.gov
обсуждение исходный текст
Ответ на Re: BUG #6612: Functions can be called inside CHECK statements  (Greg Stark <stark@mit.edu>)
Ответы Re: BUG #6612: Functions can be called inside CHECK statements  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #6612: Functions can be called inside CHECK statements  (Greg Stark <stark@mit.edu>)
Список pgsql-bugs
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: BUG #6612: Functions can be called inside CHECK statements
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: Broken Pipe Error