Re: a trigger question - Mailing list pgsql-general

From Oliver Elphick
Subject Re: a trigger question
Date
Msg-id 1023292771.23631.8.camel@linda
Whole thread Raw
In response to a trigger question  ("Zhou, Lixin" <LZhou@illumina.com>)
List 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.Elphick@lfix.co.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

Attachment

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: a trigger question
Next
From: "Peter A. Daly"
Date:
Subject: Re: Insight into indexes? (or inverting then externally)