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 1s2J4R-001uAK-K8 for pgsql-sql@arkaria.postgresql.org; Wed, 01 May 2024 23:09:03 +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 1s2J4N-00Efxu-1J for pgsql-sql@arkaria.postgresql.org; Wed, 01 May 2024 23:08:59 +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 1s2J4M-00Efxm-HM for pgsql-sql@lists.postgresql.org; Wed, 01 May 2024 23:08:59 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s2J4A-000zpW-2j for pgsql-sql@postgresql.org; Wed, 01 May 2024 23:08:58 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7def44cfadeso15608839f.1 for ; Wed, 01 May 2024 16:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714604924; x=1715209724; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ej+ffYtYYAasvzJ1RR3I7vZcJgF92f473gf8R5xP3Lw=; b=aWpFPUTYiretRFGL2g+u1xSE8Qpz9gXuvxUx/iX/NHBwNUbN2WLgPrGM/1C3+s06y5 Izv6SpbdiV/6UggTLJghVURLtW8JafEICPrtyPSvIl7abh0RctqA/g6RciorMHjidAlz u+QmrrYqHHhPlirVc6MtdyiqANDSBfI91aWDZbM9tTOhMxTlN8w2DdbkM58EajT9Zj/A YUBb5WP/NfAvbjkSWM2vRxTf07OANBvSzG3Gyr6PY9uoaaACQZIUG9Pq9hhsAt2J+GDD L8cTdU98L2AD9zIlH+si9eXwdHlaBojfjRibJvyPTW2FgpaJP6QoywyscwcpKr00N5qB 2ZrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714604924; x=1715209724; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ej+ffYtYYAasvzJ1RR3I7vZcJgF92f473gf8R5xP3Lw=; b=Mco9Vp6/FYsPCopNdZS+g5YtQ/dJbePp54sU4zYcHNnBHFMkOtIhOmRXD1S3ERnsot YZ0b8x0nn2UVbRlxh6N4n8Sw4A9yMka5SqbK9t46kY//paQrYJlkinCGMQSbWq24TDoB XvWwCngKQK3oqxMrlXaoC5F1EV+7P7X2ANp9k8a4W/q3O+3nr0+xz3XgT+3U6pC6wXbm DmpzRtZK8aMkEis3mjURoG52dCfvQh2FTkK/1MhhX0VuvA7gxR2lwOjqcDsPAGAs5cUx Njoxp4shd4rttGGEloA46NoT+alTQ9QjOgahqiqX7QjtgH27HvA+5tvL2CeL7DpZvduZ Zirw== X-Gm-Message-State: AOJu0YyLEmEoQEz7MZPtTlI89zdi8CjETLs+kW48asFvbuK7qKdWbU/1 kNwrcuRSkNZIrYz5i3QmI0rPJpcOOwZdoeqGw/pLGhs9qybzlOMtUGylaQ2Bk9rjc83i0/aDyER Dkxl+rPioEjRzJuCoOl/yJ/HNOlw3HHgZ X-Google-Smtp-Source: AGHT+IH5yw0YYJNz6EFl6NRqVbClZ1NUGhc3XxYaq9nVncP+QPiAd0fUsge81+oZmTWKWq8csvbW4G44tZ/isiPQIZ8= X-Received: by 2002:a05:6e02:1a04:b0:36c:4ca4:2871 with SMTP id s4-20020a056e021a0400b0036c4ca42871mr1048513ild.4.1714604924422; Wed, 01 May 2024 16:08:44 -0700 (PDT) MIME-Version: 1.0 From: JORGE MALDONADO Date: Wed, 1 May 2024 18:08:33 -0500 Message-ID: Subject: One parent record with 3 possible child records To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary="0000000000007352d106176c91af" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007352d106176c91af Content-Type: text/plain; charset="UTF-8" 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 associated to tblMain. I am not sure how to design a case like this. I will very much appreciate your feedback. Best regards, Jorge Maldonado --0000000000007352d106176c91af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

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

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

The rela= tion between tblMain=C2=A0and tblOne is 1:1.
The relation between= tblMain=C2=A0and tblTwo is 1:1.
The relation between tblMain=C2= =A0and tblThree is 1:1.

Is it better to set tblMai= n=C2=A0as parent or child?

This can be seen as if = tblOne, tblTwo and tblThree extend=C2=A0tblMain=C2=A0depending=C2=A0on a sp= ecific criteria.

Let's say that tableMain = has a string field called "type" with the following possible valu= es: "residential", "industrial" and "energy".= =C2=A0

I will always insert a record in tblMain bu= t:
* If type is "residential" then a record in tblOne i= s created and it is associated to tblMain,=C2=A0
* If type is &qu= ot;industrial" a record in tblTwo is created and it is associated to t= blMain
* If type is "energy" a record in tblThree=C2=A0= is created=C2=A0and it is associated to tblMain.

I= am not sure how to design a case like this. I will very much appreciate yo= ur feedback.

Best regards,
Jorge Maldona= do

--0000000000007352d106176c91af--