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 1s2XVv-003rwU-QZ for pgsql-sql@arkaria.postgresql.org; Thu, 02 May 2024 14:34:23 +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 1s2XVt-00137W-Cb for pgsql-sql@arkaria.postgresql.org; Thu, 02 May 2024 14:34:22 +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 1s2WZk-000aMF-Gv for pgsql-sql@lists.postgresql.org; Thu, 02 May 2024 13:34:17 +0000 Received: from mail-ej1-f51.google.com ([209.85.218.51]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s2WZi-0015Y5-HQ for pgsql-sql@postgresql.org; Thu, 02 May 2024 13:34:16 +0000 Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a5544fd07easo1096819766b.0 for ; Thu, 02 May 2024 06:34:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714656853; x=1715261653; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=txUBY2w6tRyW4ig9IntWWESWwuEy39MOCZJI+0s1SHQ=; b=h2LSTGmjV+MQQE+/5p4ZpUGsDCWEC/L8XXcgYsNP/ZnuMrxYxj5MGvgmfB8hKitKbw rPLd/z+75ytKbJcjR8614BEQKUv7xm4Ew6CAfbIIGv9/5SMnGB9oomu4UFecaUuf3poS kKL/XDRiyuSiOTQrUtuRPQcnt+/hdXU0Oid2MCT3XS4briKH2LfOGpt6xZx4JY5bQ+yN sj51/5jDyclvADDWfiJH9IuxaGloh4z8juwOgwjTu3gIp+7SK2n0KAZegZVjRMKPMg+s nFYDXLGNCfu5GUG4uzNK3Gp1V/He2zlAAXM59snDM9kQ9qwO8oEiYAacUJIJwuTRssXK JCgA== X-Gm-Message-State: AOJu0YwtmIv0WPwdsTJPEoR87dU5PNjlLaKpDmITp9h5pwGr/o2ngu5I qbhAL4hLnJx58QlrMGV+iraH1pumUFBoPRukKOsm6VhOPih3uGIOxVWVyz2d X-Google-Smtp-Source: AGHT+IHBdiOFQ/Houy+3uJyiUYXL+FIM9RnPD/b1SZNtGG8L8fglnvkk2WTbYsb+VBc6+5E8SBW8HQ== X-Received: by 2002:a17:906:6b90:b0:a52:36e1:c139 with SMTP id l16-20020a1709066b9000b00a5236e1c139mr3357374ejr.4.1714656852163; Thu, 02 May 2024 06:34:12 -0700 (PDT) Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com. [209.85.218.47]) by smtp.gmail.com with ESMTPSA id bn23-20020a170906c0d700b00a51a60bf400sm567062ejb.76.2024.05.02.06.34.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 May 2024 06:34:11 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a5878caeb9eso998566466b.1 for ; Thu, 02 May 2024 06:34:11 -0700 (PDT) X-Received: by 2002:a50:cd17:0:b0:572:1589:eb98 with SMTP id z23-20020a50cd17000000b005721589eb98mr3682065edi.12.1714656851703; Thu, 02 May 2024 06:34:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sanjay Minni Date: Thu, 2 May 2024 19:03:44 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: One parent record with 3 possible child records To: JORGE MALDONADO Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary="0000000000008ec923061778a8db" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008ec923061778a8db Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable maybe unorthodox but if its certain to be 1:1 then why not flatten it to a single table with all the possible columns (tblMain+tblOne+tblTwo+tblThree). You can keep a flag to indicate the type. there may be a gain in simplicity without losing anything. Sanjay On Thu, May 2, 2024 at 4:39=E2=80=AFAM JORGE MALDONADO wrote: > Hi, > > I have one table that can have relations to only 1 of 3 possible tables. > For example: tblMain*,* tblOne, tblTwo and tblThree. > > I will always have 1 record in tblMain but each record in this table will > be related to one record in tblOne OR one record in tblTwo OR one record = in > tblThree. > > The relation between tblMain and tblOne is 1:1. > The relation between tblMain and tblTwo is 1:1. > The relation between tblMain and tblThree is 1:1. > > Is it better to set tblMain as parent or child? > > This can be seen as if tblOne, tblTwo and tblThree > extend tblMain depending on a specific criteria. > > Let's say that tableMain has a string field called "type" with the > following possible values: "residential", "industrial" and "energy". > > I will always insert a record in tblMain but: > * If type is "residential" then a record in tblOne is created and it is > associated to tblMain, > * If type is "industrial" a record in tblTwo is created and it is > associated to tblMain > * If type is "energy" a record in tblThree is created and it is associate= d > to tblMain. > > I am not sure how to design a case like this. I will very much appreciate > your feedback. > > Best regards, > Jorge Maldonado > > --0000000000008ec923061778a8db Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
maybe unorthodox=C2=A0but if its certain to be 1:1 then why not= flatten it to a single=C2=A0table with all the possible columns (tblMain+t= blOne+tblTwo+tblThree). You can keep a flag to indicate the type. there may= be a gain in simplicity without losing anything.

Sanjay=C2=A0=C2=A0

On Thu, May 2, 2024 at 4:39=E2=80=AFAM JORGE MALDONADO <jorgemal1960@gmail.com> wrote:
Hi,

I have one table that ca= n have relations to only 1 of 3 possible tables. For example:=C2=A0tblMain<= b>,=C2=A0tblOne, tblTwo and tblThree.=C2=A0

I = will always have 1 record in tblMain=C2=A0but each record in this table wil= l be related to one record in tblOne OR one record in tblTwo OR one record = in tblThree.=C2=A0

The relation between tblMain=C2= =A0and tblOne is 1:1.
The relation between tblMain=C2=A0and tblTw= o is 1:1.
The relation between tblMain=C2=A0and tblThree is 1:1.<= /div>

Is it better to set tblMain=C2=A0as parent or chil= d?

This can be seen as if tblOne, tblTwo and tblTh= ree extend=C2=A0tblMain=C2=A0depending=C2=A0on a specific criteria.

Let's say that tableMain has a string field calle= d "type" with the following possible values: "residential&qu= ot;, "industrial" and "energy".=C2=A0

I will always insert a record in tblMain but:
* If type i= s "residential" then a record in tblOne is created and it is asso= ciated to tblMain,=C2=A0
* If type is "industrial" a re= cord in tblTwo is created and it is associated to tblMain
* If ty= pe is "energy" a record in tblThree=C2=A0is created=C2=A0and it i= s associated to tblMain.

I am not sure how to desi= gn a case like this. I will very much appreciate your feedback.
<= br>
Best regards,
Jorge Maldonado

<= /div>
--0000000000008ec923061778a8db--