Re: foreign key violation error with partitioned table

From: SHARMILA JOTHIRAJAH <sharmi_jo(at)yahoo(dot)com>
To: gunce orman <guncepostgres(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: foreign key violation error with partitioned table
Date: 2007-09-06 13:37:28
Message-ID: 533177.31903.qm@web31115.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The postgresql partitions is done using inheritance . So basically your master table is empty and the child tables(partitions) contains all the records...right. You can check if your master table contains any records by using this query
SELECT * FROM ONLY <master_table_name>
This will return zero if your master table is empty.

So when you reference your master table from other tables, it will always give FK violation since your master table is empty and the recs are in child tables only.

Shar joe

gunce orman <guncepostgres(at)gmail(dot)com> wrote: hello,

i have a partitioned table t_kayit with 6 partitions and kayit_id is primary key on this table. My other t_vto_sonuclari table use that kayit_id as foreign key. I'm trying to insert values which contains kayit_id to t_vto_sonuclari and i'm sure those kayit_ids are in t_kayit table too but when i'm inserting , i had error.

ERROR: insert or update on table "t_vto_sonuclari" violates foreign key constraint "fk_t_kayit_kayit_id"
DETAIL: Key(kayit_id)=(54168) is not present in table t_kayit

I created a new test table which is totally same as t_kayit but non partitioned . I create new foreign key on that t_vto_sonuclari which refers to the new test table. In that case i didn't had that error.I could insert. what am i supposed to do for partitioned table?


---------------------------------
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2007-09-06 13:48:10 Re: PostgreSQL with Kerberos and Active Directory
Previous Message gunce orman 2007-09-06 13:26:59 foreign key violation error with partitioned table