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 1qnVtX-00B71r-O2 for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2023 03:16: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 1qnVtW-000Bmg-8N for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2023 03:16: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 1qnVtV-000Bly-Or for pgsql-sql@lists.postgresql.org; Tue, 03 Oct 2023 03:16:22 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qnVtT-007tsN-Jh for pgsql-sql@lists.postgresql.org; Tue, 03 Oct 2023 03:16:20 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c724577e1fso3469785ad.0 for ; Mon, 02 Oct 2023 20:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696302858; x=1696907658; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pV4QCcgifTtvyHhTrWD6NH9EW8Ck3/wzAAVzSyByV2o=; b=hTBxdNKB1DWG39DhS4JgBdi10+DYoj78frZ7v1lIHAKAhoH7vnVXfnsd5w8lyF8aoE FHQ5Q61puw1QJGKXPZ5OhLM7lPoV1WD5uh+iCgJUKoTfFPpQOkg8iBHjgqAC7/kjnMw0 EBVn/5G9OTBIqC+3h+9I93B44e+DSepxruEgzujq2CrCAx4dFuy+DdQMERFLdAk65M4Q BdSIAMPbbOWdxCToNGAe4syKv3DWT7iJD4ji5wyoA5N1yECOBFKrfao2/87UEVwXVsVW 41M7hcRHPW2K5HT/ePV75mx2mrgrzZ7BZjnW91km70PzO+cyZPo3zceetvWIS7TzT5D0 bwoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696302858; x=1696907658; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pV4QCcgifTtvyHhTrWD6NH9EW8Ck3/wzAAVzSyByV2o=; b=j3aeDziO3YUhBiHZDjH9NCl6lPQp34GF7x5ZvTwvx9xOGtiqiPJ3IieyhwItCqJcIv /AHq8ftWvF26fJHdyiq3/AGcpaeH621W6B1hbDhpOCOd5JHGroG8UQuUGMvhm4o07MN3 PtsqPDTWT/neBJrEmJkNCB429e1uftD9xnTugcnqoYLhNKBT87dvl9AkdtTv8dBkE5bs 7zNY1uXWVld52vHnMoT8AVPCY+6uQNuKswLgE3oe/xOgEa4F4qDh7tZVK71NtMoKqual p2qGMXl9/NiA/YDZMf+dkbO572QqMPF51R3FNJjD1l3jrFlKLg5GTmzZIWIsFx3ZyDPa /jag== X-Gm-Message-State: AOJu0YwzyTNUrbhbyr5FhGOL5RC8kwixfIecmNNCUjfyTSvcxuX7GgPg gEexM0j6vyxwq2bkZxTCmNkNFyfAYpA= X-Google-Smtp-Source: AGHT+IFUBgvF0Rmkxs0EXDQCXrkTvFyZm9AHWLiJLB38Rp62v4m6jpqs+0QiweJYpQ7y1Lr1QFJDXQ== X-Received: by 2002:a17:903:187:b0:1c6:2d13:5b77 with SMTP id z7-20020a170903018700b001c62d135b77mr18409281plg.39.1696302857789; Mon, 02 Oct 2023 20:14:17 -0700 (PDT) Received: from ?IPV6:2601:681:5a00:f790:856a:34eb:32f:40ee? ([2601:681:5a00:f790:856a:34eb:32f:40ee]) by smtp.gmail.com with ESMTPSA id jh19-20020a170903329300b001b3bf8001a9sm223242plb.48.2023.10.02.20.14.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Oct 2023 20:14:17 -0700 (PDT) Message-ID: <14719fdf-108a-edb6-fd74-0c42669bcfb4@gmail.com> Date: Mon, 2 Oct 2023 21:14:16 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: A situation with one parent table and 3 child tables Content-Language: en-CA To: pgsql-sql@lists.postgresql.org References: <2206102.1696302184@sss.pgh.pa.us> From: Rob Sargent In-Reply-To: <2206102.1696302184@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/2/23 21:03, Tom Lane wrote: > "David G. Johnston" writes: >> On Monday, October 2, 2023, JORGE MALDONADO 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"