Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Question Unanswered: 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?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    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.

  3. #3
    Join Date
    Apr 2011
    Posts
    2
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •