public inbox for [email protected]
help / color / mirror / Atom feedFrom: David G. Johnston <[email protected]>
To: Tom Lane <[email protected]>
Cc: JORGE MALDONADO <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: A situation with one parent table and 3 child tables
Date: Mon, 2 Oct 2023 20:10:12 -0700
Message-ID: <CAKFQuwa6-C9V8nVB6CkX8P0y_b675HZRjp4uqiMqLWD0x1=TFA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAAY=A7_wHBKkKFxuxXc7A+fr3TYGmWS9-hCGghLRDcQAAa_wfQ@mail.gmail.com>
<CAKFQuwZbmqeLoHBzuOkVjd4qXyNUi1tcuhf8bECK+2c-DGK9iw@mail.gmail.com>
<[email protected]>
On Monday, October 2, 2023, Tom Lane <[email protected]> wrote:
> "David G. Johnston" <[email protected]> writes:
> > On Monday, October 2, 2023, JORGE MALDONADO <[email protected]>
> 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.
>
This sounds like a typical subclassing (animal -> {dog,cat,moose})
structure where I am assuming the children have different subtype-specific
columns.
David J.
view thread (6+ messages) latest in thread
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: A situation with one parent table and 3 child tables
In-Reply-To: <CAKFQuwa6-C9V8nVB6CkX8P0y_b675HZRjp4uqiMqLWD0x1=TFA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox