From: | Rob Sargent <robjsargent(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)lists(dot)postgresql(dot)org |
Subject: | Re: A situation with one parent table and 3 child tables |
Date: | 2023-10-03 03:14:16 |
Message-ID: | 14719fdf-108a-edb6-fd74-0c42669bcfb4@gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 10/2/23 21:03, Tom Lane wrote:
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
>> On Monday, October 2, 2023, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> wrote:
>>> 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 with
>>> 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 about
>>> 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 know
>>> 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
>
>
I've implemented David's suggestion in the past. Presumably the three
child tables are of different structure but share the attributes of the
"parent"
From | Date | Subject | |
---|---|---|---|
Next Message | Japin Li | 2023-10-12 07:06:17 | Could not use index because of indcheckxmin is true |
Previous Message | David G. Johnston | 2023-10-03 03:10:12 | Re: A situation with one parent table and 3 child tables |