Re: INHERIT and FOREIGN KEY issues

From: Kedar Rasik Parikh <kedarr(at)netcore(dot)co(dot)in>
To: Luiz Eduardo Cantanhede Neri <lecneri(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: INHERIT and FOREIGN KEY issues
Date: 2009-05-24 19:27:51
Message-ID: 20090525005751.vfm0ui92wwkswc4k@port1.netcore.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

We use partitioning and inheritance to a great extent to manage our
massive tables, I just hope that partitioning will be as simple,
effective and free from hacks and work around as it is in Oracle.

I love postgres otherwise.

- Kedar Parikh

Quoting Luiz Eduardo Cantanhede Neri <lecneri(at)gmail(dot)com>:

> Just a correction, I were recreating Primary key wrongly. Recreating the
> primary key @ child table worked too
>
> On Sun, May 24, 2009 at 3:26 PM, Luiz Eduardo Cantanhede Neri <
> lecneri(at)gmail(dot)com> wrote:
>
>> My workaround to this was create a unique key serial @ childtable and use
>> this unique key as foreign key. But I really dont like this.
>>
>> I tried to recreate the primary key again, but didnt work either
>>
>>
>> On Sun, May 24, 2009 at 3:11 PM, Kedar Rasik Parikh
>> <kedarr(at)netcore(dot)co(dot)in>wrote:
>>
>>> I believe you will have to say good bye to the foreign key constraint.
>>>
>>> Its is not inherited, only the schema is, constraints and index will have
>>> to be separately created per child table.
>>>
>>>
>>> -Regards
>>>
>>> Kedar Parikh
>>>
>>>
>>>
>>> Quoting Luiz Eduardo Cantanhede Neri <lecneri(at)gmail(dot)com>:
>>>
>>> Hi,
>>>> I'm trying to do something like this:
>>>>
>>>> BEGIN;
>>>>
>>>> CREATE TABLE A
>>>> (
>>>> idA serial not null primary key,
>>>> someColumn text
>>>> );
>>>>
>>>> CREATE TABLE B
>>>> (
>>>> someData text
>>>> ) INHERITS(A);
>>>>
>>>> CREATE TABLE C
>>>> (
>>>> idC serial not null primary key,
>>>> anotherColumn text
>>>> );
>>>>
>>>> CREATE TABLE BC(
>>>> idB int4,
>>>> idC int4,
>>>> FOREIGN KEY (idB) REFERENCES B(idA),
>>>> FOREIGN KEY (idC) REFERENCES C(idC)
>>>> );
>>>>
>>>> COMMIT;
>>>>
>>>> But When it is going to create the table BC, it gives an error:
>>>>
>>>> ERROR: there is no unique constraint matching given keys for referenced
>>>> table "b"
>>>>
>>>> My question is: Shouldn't it get Table A primary key and create the
>>>> foreign
>>>> key?
>>>>
>>>> Thx
>>>> Luiz Eduardo
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message vy 2009-05-25 00:28:39 Re: Create Database/Tables -PostgreSQL
Previous Message Luiz Eduardo Cantanhede Neri 2009-05-24 18:35:30 Re: INHERIT and FOREIGN KEY issues