Table Inheritance and Foreign Keys

From: "Riaan Stander" <rstander(at)exa(dot)co(dot)za>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Table Inheritance and Foreign Keys
Date: 2019-02-17 22:11:22
Message-ID: 003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-02-17 22:58:55 Re: Table Inheritance and Foreign Keys
Previous Message legrand legrand 2019-02-17 21:52:07 pg_stat_statements doesn't track commit from pl/pgsql blocks