Re: Triggers

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Triggers
Date: 2002-08-16 15:08:45
Message-ID: 1029510525.4031.568.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2002-08-16 at 15:14, Tom Lane wrote:
> Oliver Elphick <olly(at)lfix(dot)co(dot)uk> writes:
> >> Unfortunately the column is defined as not null so I fear the insert
> >> would fail and the trigger never get called. How can I get around this?
>
> > Surely you can use a BEFORE trigger, can't you?
>
> I think we check constraints (including NOT NULL) before firing
> triggers.

No, I just tried it (in 7.2.1). The BEFORE trigger successfully
replaced a null, thus satisfying the constraint.

> The simple answer to this is not to use a constraint, but to rely on
> insert and update triggers to substitute for a null (or throw an error)
> in that column.
>
> regards, tom lane
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"And whatsoever ye shall ask in my name, that will I
do, that the Father may be glorified in the Son."
John 14:13

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ian Harding 2002-08-16 15:40:46 Re: last entry
Previous Message Tom Lane 2002-08-16 14:58:04 Re: Triggers