a trigger question - Mailing list pgsql-general

From Zhou, Lixin
Subject a trigger question
Date
Msg-id 6EDF654BC7BFE648AB2E734727E7078DAEC76D@illumina24.illumina.com
Whole thread Raw
Responses Re: a trigger question  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Re: a trigger question  (Oliver Elphick <olly@lfix.co.uk>)
Re: a trigger question  (Jan Wieck <janwieck@yahoo.com>)
Re: a trigger question  (Manfred Koizar <mkoi-pg@aon.at>)
List pgsql-general
Give two tables A and B.  B has a field that references A's primary key.

For example:

create table A(
    i int not null,
    s text,
    primary key(i));

create table B(
    i int not null,
    s text,
    primary key(i),
    foreign key(i) references A(i));

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?

Thanks!

Lixin Zhou




pgsql-general by date:

Previous
From: "Bob Powell"
Date:
Subject: Aliias names in select criteria
Next
From: "sheetal"
Date:
Subject: Help...