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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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