foreign key constraints and inheritence - Mailing list pgsql-general

From Garrett Kalleberg
Subject foreign key constraints and inheritence
Date
Msg-id 59057EB0-2099-4C9F-AAE4-67E6DEE917BD@metadada.com
Whole thread Raw
Responses Re: foreign key constraints and inheritence
List pgsql-general
I have this structure:

CREATE TABLE invoicelineitemtypes (
     invoicelineitemtypeid varchar(36) PRIMARY KEY,
     otherstuff varchar(36)
);

CREATE TABLE invoicelineiteminventorytypes (
     moresetuff varchar(36)
)
INHERITS (invoicelineitemtypes);

CREATE TABLE invoicelines (
     invoicelineitemtypeid varchar(36) REFERENCES
invoicelineitemtypes ON DELETE CASCADE,
     otherstuff varchar(36)
);

INSERT INTO invoicelineiteminventorytypes (invoicelineitemtypeid)
VALUES ('1234');

The following insert:

INSERT INTO invoicelines (invoicelineitemtypeid) VALUES ('1234');

invokes

"insert or update on table "invoicelines" violates foreign key
constraint "invoicelines_invoicelineitemtypeid_fkey"

Now, the rec with id '1234' is in the table
invoicelineiteminventorytypes, but I can't wrap my head around the
fact that

SELECT invoicelineitemtypeid FROM invoicelineitemtypes

yields the rec with invoicelineitemtypeid '1234', yet I can't
reference it in the invoicelines INSERT statement.

Am I missing something? Is there a workaround for this?

PostgreSQL 8.0.1 running on OS X 10.4.2.



Garrett

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: encoding and locale
Next
From: "Michael Schmidt"
Date:
Subject: Re: How to create unique constraint on NULL columns