Table Inheritance and Foreign Keys - Mailing list pgsql-general

From Riaan Stander
Subject Table Inheritance and Foreign Keys
Date
Msg-id 003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za
Whole thread Raw
Responses Re: Table Inheritance and Foreign Keys  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

Good day

 

I’ve got a scenario where I’m building a table structure that allows for building a tree. In order to properly separate the different column requirements I’ve looked at using table inheritance.

Example structure:

 

CREATE TABLE base_table

(

    id    bigint primary key,

    parent_id    bigint,

    some_common_columns ….

)

 

CREATE TABLE folder

(

    id    bigint primary key,

    some_folder_specific_columns …

) INHERITS(base_table)

 

CREATE TABLE node_type_x

(

    id    bigint primary key,

    some_node_x_specific_columns….

) INHERITS (base_table)

 

Now obviously when inserting folders and node type x records they would go to their respective tables, but with the table inheritance I can query base_table to get them all.

The rules state that folders can only be inserted under folders, but node type x can go under folders or other node type x’s.

 

Now if I want to add a foreign key to the base table from node type x I get an error due to Postgres not supported this scenario. The documentation talks about this, but also state as follows

These deficiencies will probably be fixed in some future release, but in the meantime considerable care is needed in deciding whether inheritance is useful for your application”

 

My question is if anybody knows more as to if and when this actually will be allowed/solved.

 

Regards

Riaan

pgsql-general by date:

Previous
From: legrand legrand
Date:
Subject: pg_stat_statements doesn't track commit from pl/pgsql blocks
Next
From: Tom Lane
Date:
Subject: Re: Table Inheritance and Foreign Keys