Search Postgresql Archives

Table Inheritance and Foreign Keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux