Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvUfP-0005xa-Bp for pgsql-general@arkaria.postgresql.org; Sun, 17 Feb 2019 22:12:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gvUfN-0001u4-VA for pgsql-general@arkaria.postgresql.org; Sun, 17 Feb 2019 22:12:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvUfN-0001tx-JB for pgsql-general@lists.postgresql.org; Sun, 17 Feb 2019 22:12:05 +0000 Received: from outgoing30.cpt4.host-h.net ([196.40.103.60]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvUfG-0002e0-7U for pgsql-general@postgresql.org; Sun, 17 Feb 2019 22:12:03 +0000 Received: from www20.cpt1.host-h.net ([197.221.2.20]) by antispam5-cpt4.host-h.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1gvUf6-0006rQ-90 for pgsql-general@postgresql.org; Mon, 18 Feb 2019 00:11:51 +0200 Received: from [155.93.246.199] (helo=DMZHOST) by www20.cpt1.host-h.net with esmtpa (Exim 4.84_2) (envelope-from ) id 1gvUf4-0000no-TH for pgsql-general@postgresql.org; Mon, 18 Feb 2019 00:11:47 +0200 Received: from Win8Dev (Unknown [10.0.0.41]) by DMZHOST with ESMTPA ; Mon, 18 Feb 2019 00:11:31 +0200 From: "Riaan Stander" To: Subject: Table Inheritance and Foreign Keys Date: Mon, 18 Feb 2019 00:11:22 +0200 Message-ID: <003501d4c70d$b7a8c3e0$26fa4ba0$@exa.co.za> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0036_01D4C71E.7B320910" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdTHDEfLGQQ3NbBjR72nl2amzQ46CA== Content-Language: en-za X-Authenticated-Sender: smtprelay@exa.co.za X-Virus-Scanned: Clear (ClamAV 0.100.2/25363/Sun Feb 17 13:12:54 2019) X-Originating-IP: 197.221.2.20 X-SpamExperts-Domain: exa.co.za X-SpamExperts-Username: Authentication-Results: host-h.net; auth=pass (login) smtp.auth=@exa.co.za X-SpamExperts-Outgoing-Class: unsure X-SpamExperts-Outgoing-Evidence: Combined (0.49) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5s/Ds6AiE+t65lqzHFJbXH9602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvOytUBiMvsajJA+7b2BHTXuSMHHqQxHQMrHuisIWO0uIZVTGbEWWnE2yTxqfzAQugcSH8 bgB60pQADM5xJBSVNVtIeZjZv1oz6oWKgngYgisMi23y8jmHeT9JKEjdVEX1rwYlyGht/UGBAIfG wWiAT6uW+gCmutls5ccQuVDVo4TP+gURVY11G4kRB/JpUdSbT67CcOtOgkC656SEeN2HNL2+zaYs Gd3zvIsWfWWmmrJ3gWkCIn3WhszKF3IF5zl37EQMF99VlWOZVo1sbhkkbsVaRqrPKRVcIFx9gW7Q zdWydUmuadzRFBdGamrPI50dHQkmr0Aaz6GoBF32dtdAsfG8Ksk+aedMfNWSnJswrtlNo0J4GLK2 ImpBn+9D+XUmmsGj1Y+LggTjknxIwgFawDt5qZW8mIePsNN3rN9js430qOSYcJPoTEymKabgNgWl noqUz1jBxlKrjhTaVvUepzHfUy6xfZdyLRnwP1q5wC1enmybWvc6QsCpVANmsLF0QuG187kbUIBj BEzUXAehyxXFOAJuKbwBO09xqfKx0A0vVeHBACW9zKjL85WI4TFcH94oWNvWjSYevZ6rcMXkUCek 1x9NSLZosXDypj5qTkQ0qvH6+iXSv95uOd0oVQEv5NCNldHtRKEU7KCqAI4HqZFCPrbjZ58YyU7w FVIiv4IqxGdFhs80F8jOjHoA1VaUsHLYM3A6BXfvel8OEFDbU52fAUyKMzs1pJkSONhSPoDxIsKK 27pz5GBDshzLdtcikG2r9QJw1BMO8WIjL3ToSbJWyXwDxReKVx7Gw7dyNG9JbCB/BBd46AYXoop3 Vb1ozADS46avlCR8d7Pi67MCE2hbX8aRYf/GCb6+tkdwibnWiI7OjFgkPwqrBdPJt9hrc/Y4ocfm Wv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@antispammaster.host-h.net List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multipart message in MIME format. ------=_NextPart_000_0036_01D4C71E.7B320910 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_0036_01D4C71E.7B320910 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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

“T= hese 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”

<= o:p> 

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

<= o:p> 

R= egards

R= iaan

------=_NextPart_000_0036_01D4C71E.7B320910--