Re: a trigger question

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: "Zhou, Lixin" <LZhou(at)illumina(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: a trigger question
Date: 2002-06-05 15:59:31
Message-ID: 1023292771.23631.8.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2002-06-04 at 21:21, Zhou, Lixin wrote:

> I like to create a trigger on table A. When a new row is inserted into A
> (ex: with i = 5), I like to have the trigger inserts a new row in table B
> whose field "i" has the same value as that of the A's (ex: i = 5).
>
> As I do this, the error message is something like: "referential integration
> violation - key referenced in B not found in A". This makes sense to me
> since at the time the trigger inserts in B, A's new row is not visible yet
> -- not committed yet.
>
> How can I solve this problem using trigger?

Declare the foreign key constraints deferrable and defer them in the
session; they will be checked only at the end of the transaction.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"Let your conversation be without covetousness; and be
content with such things as ye have. For he hath said,
I will never leave thee, nor forsake thee."
Hebrews 13:5

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter A. Daly 2002-06-05 16:09:22 Re: Insight into indexes? (or inverting then externally)
Previous Message Stephan Szabo 2002-06-05 15:53:44 Re: a trigger question