Inheritance, shared primary keys between parent and child tables. - Mailing list pgsql-novice

From James McCarthy
Subject Inheritance, shared primary keys between parent and child tables.
Date
Msg-id CAGvkbhcFO+bg-Et4-JiWL-E7WCa9BcnZM9Wvmzwkg9SkZ7BE7A@mail.gmail.com
Whole thread Raw
Responses Re: Inheritance, shared primary keys between parent and child tables.  (David Johnston <polobo@yahoo.com>)
List pgsql-novice
I thought the primary key was NOT shared between parent/child tables through inheritance.

On reading the documentation section for inheritance in Postgresql
 It seems obvious that the primary key of the parent table is not shared by the child table(am I miss-understanding?)

My experience from playing around with this indicates otherwise.

For example

  CREATE TABLE account (
 id SERIAL PRIMARY KEY
);

  CREATE TABLE account_admin (
 cash INTEGER
)INHERITS (account);

  CREATE TABLE account_user (
 credit INTEGER
)INHERITS (account);


INSERT INTO account_admin(cash) VALUES(12);
INSERT INTO account_user(credit) VALUES(12);
INSERT INTO account_user(credit) VALUES(12);
INSERT INTO account_admin(cash) VALUES(12);

My understanding of the documentation is:

SELECT id FROM account_admin;

should return 1,2

actually returns: 1,4;

And:

SELECT id FROM account_user;
should return: 1,2
actually returns: 2,3

While 
SELECT id FROM account;
returns: 1,2,3,4 as expected


Does this mean that child tables of a parent share the same primary key?



pgsql-novice by date:

Previous
From: Henry Drexler
Date:
Subject: Re: moving postgresql's data directory
Next
From: David Johnston
Date:
Subject: Re: Inheritance, shared primary keys between parent and child tables.