Re: Precedence of a TRIGGER vs. a CHECK on a column

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Precedence of a TRIGGER vs. a CHECK on a column
Дата
Msg-id 10219.1074544052@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Precedence of a TRIGGER vs. a CHECK on a column  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-general
Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> I think it's that your domain constraint is being applied before the
> trigger is executed and that the table constraints are being applied
> after given that I get the same behavior with a domain constraint of not
> null.  This makes sense (although I haven't checking the spec wording)
> since the value is being coerced into the domain in order to be put into
> the row that's being passed to the trigger (thus triggering the domain
> constraints).

IIRC other datatype-related constraints, such as max length for a
char(n) or varchar(n) column, are also checked before triggers are
fired.  We have had complaints about that before, mainly from people
who wanted to use a trigger to truncate a varchar value before the
constraint gets checked.

I think this ordering of operations is largely an implementation
artifact and could in theory be changed, but I'm disinclined to change
it unless someone can show that the spec requires different behavior.
In particular, ISTM that if we change it, the input to the trigger
wouldn't really be a legal value of the table's rowtype.

            regards, tom lane

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

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Detecting database corruption
Следующее
От: "scott.marlowe"
Дата:
Сообщение: Re: [pgsql-advocacy] New PostgreSQL search resource