Skip site navigation (1) Skip section navigation (2)

Re: how to create a record when reference is required

From: Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com>
To: java4dev <java4dev(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to create a record when reference is required
Date: 2011-05-03 10:23:36
Message-ID: 5B5E6F5A-AD65-4E76-B543-ED890784374D@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-novice
On May 3, 2011, at 2:47 PM, java4dev wrote:

> insert into a values (1,1);
> insert into b values (1,1);
> insert into b values (2,1);
> 
> I get
> 
> ERROR:  insert or update on table "a" violates foreign key constraint "rfr_main_b"
> DETAIL:  Key (fk_main_b_id)=(1) is not present in table "b".
> 
> ********** Error **********


Try something like:
BEGIN;
set constraints all deferred;
INSERT statement;
INSERT statement;
COMMIT;

Thanks & Regards,
Vibhor Kumar
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
vibhor(dot)kumar(at)enterprisedb(dot)com
Blog:http://vibhork.blogspot.com


In response to

pgsql-novice by date

Next:From: raghu ramDate: 2011-05-03 10:54:34
Subject: Can we Flush the Postgres Shared Memory ?
Previous:From: Willy-Bas LoosDate: 2011-05-03 10:23:16
Subject: Fwd: how to create a record when reference is required

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group