Thread: Foriegn key constraint

Foriegn key constraint

From
"Sivagami ."
Date:
Hi,
 
I have a question. I tried adding a Foreign Key constraint to a table via the ALTER TABLE command. But the records in the table did not match with those in the Parent table. Now my Alter table command, instead of giving me an error of kind - 'records do not match',  has gone into a kind of Deadlock between the 2 tables. I am not able to select from the tables, nor delete them, nor drop them. If I try to do any of these, I get the error saying -
" Error :  RelationBuildTriggers: 2 record(s) not found for rel invoice"
 
How do I overcome this error. Any ideas will be greatly appreciated.
Thanks a lot in advance.
 
Shiva.

RE: Foriegn key constraint

From
"Trewern, Ben"
Date:

I am pretty sure that the ALTER TABLE command does not do any checking when it creates the triggers which produce a foreign key constraint.  The DBA is assumed to have checked the tables before they create the constraint.  Best thing I can think of is to do is drop these triggers and then sort out your table before setting up your foreign key constraint.

Hope this helps

Ben

-----Original Message-----
From: Sivagami . [mailto:sivagami@worlddata.com]
Sent: 05 December 2000 22:04
To: pgsql-admin@postgresql.org
Subject: [ADMIN] Foriegn key constraint

Hi,

I have a question. I tried adding a Foreign Key constraint to a table via the ALTER TABLE command. But the records in the table did not match with those in the Parent table. Now my Alter table command, instead of giving me an error of kind - 'records do not match',  has gone into a kind of Deadlock between the 2 tables. I am not able to select from the tables, nor delete them, nor drop them. If I try to do any of these, I get the error saying -

" Error :  RelationBuildTriggers: 2 record(s) not found for rel invoice"

How do I overcome this error. Any ideas will be greatly appreciated.
Thanks a lot in advance.

Shiva.

Re: Foriegn key constraint

From
Stephan Szabo
Date:
Can you give the sequence of commands you used and the
version?

The easiest way to get rid of the message is to set the
reltriggers for the pg_class row associated to invoice
to the correct number.  It seems like the number of triggers
got updated but the triggers themselves were never added.

Stephan Szabo
sszabo@bigpanda.com

On Tue, 5 Dec 2000, Sivagami . wrote:

> Hi,
>
> I have a question. I tried adding a Foreign Key constraint to a table via the ALTER TABLE command. But the records in
thetable did not match with those in the Parent table. Now my Alter table command, instead of giving me an error of
kind- 'records do not match',  has gone into a kind of Deadlock between the 2 tables. I am not able to select from the
tables,nor delete them, nor drop them. If I try to do any of these, I get the error saying - 
> " Error :  RelationBuildTriggers: 2 record(s) not found for rel invoice"
>
> How do I overcome this error. Any ideas will be greatly appreciated.
> Thanks a lot in advance.
>
> Shiva.
>
>


Re: Foriegn key constraint

From
Jie Liang
Date:
Hi,there,

You may try use pg_dump to recover :
pg_dump -t tablename -f outfile dbname
then use vi to erase the foreign key from outfile.
drop your original tables, reload your tables
without foreign key.


Jie LIANG

Internet Products Inc.

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.ipinc.com

On Tue, 5 Dec 2000, Sivagami . wrote:


  [NON-Text Body part not included]