If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Primary key not inherited

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-11, 05:01
goocreations goocreations is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
Question Primary key not inherited

I have a simple inheritance structure:

Code:
CREATE TABLE nature_reserve
(
	the_id SERIAL PRIMARY KEY,
	the_name VARCHAR
);

CREATE TABLE private_nature_reserve
(
) INHERITS (nature_reserve);

CREATE TABLE reserve_license
(
	the_id SERIAL PRIMARY KEY,
	the_reserve INTEGER REFERENCES private_nature_reserve(the_id)
);
When I run this script I get the following error:

Code:
ERROR:  there is no unique constraint matching given keys for referenced table "private_nature_reserve"
So my question is: Aren't primary keys inherited in Postgres?
Reply With Quote
  #2 (permalink)  
Old 04-16-11, 05:53
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by goocreations View Post
So my question is: Aren't primary keys inherited in Postgres?
Straight from the manual at: http://www.postgresql.org/docs/current/static/ddl-inherit.html
Quote:
Originally Posted by Postgres manual
All check constraints and not-null constraints on a parent table are automatically inherited by its children. Other types of constraints (unique, primary key, and foreign key constraints) are not inherited.
Reply With Quote
  #3 (permalink)  
Old 04-16-11, 06:00
goocreations goocreations is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
Thank you!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On