From: | James McCarthy <dublinclontarf(at)gmail(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Inheritance, shared primary keys between parent and child tables. |
Date: | 2014-01-10 16:51:47 |
Message-ID: | CAGvkbhcFO+bg-Et4-JiWL-E7WCa9BcnZM9Wvmzwkg9SkZ7BE7A@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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
http://www.postgresql.org/docs/9.1/static/ddl-inherit.html
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?
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2014-01-10 17:15:28 | Re: Inheritance, shared primary keys between parent and child tables. |
Previous Message | Henry Drexler | 2014-01-10 15:38:43 | Re: moving postgresql's data directory |