Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnVhh-00B6SX-WF for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2023 03:04:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qnVgi-0006Vx-BD for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2023 03:03:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnVgi-0006Vo-1S for pgsql-sql@lists.postgresql.org; Tue, 03 Oct 2023 03:03:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnVgf-007tnj-MQ for pgsql-sql@postgresql.org; Tue, 03 Oct 2023 03:03:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 393334LC2206103; Mon, 2 Oct 2023 23:03:04 -0400 From: Tom Lane To: "David G. Johnston" cc: JORGE MALDONADO , "pgsql-sql@postgresql.org" Subject: Re: A situation with one parent table and 3 child tables In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Mon, 02 Oct 2023 19:53:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2206101.1696302184.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 02 Oct 2023 23:03:04 -0400 Message-ID: <2206102.1696302184@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Monday, October 2, 2023, JORGE MALDONADO wro= te: >> I have one parent table (*table_p*) with 3 child tables (*table_ch1*, *= table_ch2 >> *and *table_ch3*). Each record of the parent table can be associated wi= th >> 1 and only 1 child table records. This means that: >> = >> * Some records of the *table_p* will link to records of *table_ch1* >> * Some records of the *table_p* will link to records of *table_ch2* >> * Some records of the *table_p* will link to records of *table_ch3* >> = >> At first look, this does not make very much sense to me. I thought abou= t >> considering 3 parent tables, one for each child table. However, the 3 >> parent tables would have the same exact structure and I would like to k= now >> if there is a workaround for this issue. > You are thinking of it backwards. Your chN tables will have FK pointing > back to the p table. I suggest adding some kind of type column to the p > table indicating which chN table the row belongs to. Do you need that? I was wondering about converting the 3 child tables into a partitioned table. Then you can query them separately when you need to, but you can also treat them as one table --- and you can set up one FK constraint between that and the parent table. regards, tom lane