pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Riaan Stander <rstander@exa.co.za>
To: pgsql-general@postgresql.org
Subject: Table Inheritance and Foreign Keys
Date: Mon, 18 Feb 2019 00:11:22 +0200
Message-ID: <003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za> (raw)

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

view thread (6+ messages)  latest in thread

Message-ID: <003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za>
Permalink:  ../003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za/
Also on:    postgresql.org/message-id/003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rstander@exa.co.za
  Subject: Re: Table Inheritance and Foreign Keys
  In-Reply-To: <003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za>
  References: <003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox