Re: Precedence of a TRIGGER vs. a CHECK on a column - Mailing list pgsql-general

From Tom Lane
Subject Re: Precedence of a TRIGGER vs. a CHECK on a column
Date
Msg-id 10219.1074544052@sss.pgh.pa.us
Whole thread Raw
In response to Re: Precedence of a TRIGGER vs. a CHECK on a column  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List 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 by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Detecting database corruption
Next
From: "scott.marlowe"
Date:
Subject: Re: [pgsql-advocacy] New PostgreSQL search resource