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 1tfKV6-001T2S-NZ for pgsql-general@arkaria.postgresql.org; Tue, 04 Feb 2025 15:06:09 +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 1tfKV5-004SNg-Rp for pgsql-general@arkaria.postgresql.org; Tue, 04 Feb 2025 15:06:07 +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 1tfKUZ-004OZZ-2F for pgsql-general@lists.postgresql.org; Tue, 04 Feb 2025 15:05:35 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tfKUW-0038ei-2O for pgsql-general@postgresql.org; Tue, 04 Feb 2025 15:05:34 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5f4ce54feb8so2983262eaf.3 for ; Tue, 04 Feb 2025 07:05:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738681532; x=1739286332; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=OmmC015QrMlGvxSMXju2uqzozGJhow2yVM1ePz8K/rE=; b=dUg8SxJ6P/F4uksRGKuwT4BDhae1+Lfo/4Lugyynd7ilqFLdif2fnkZCfknSml00jf XF+FjgBQVimp8vgXT+Pv97b9gEvD171sbCbzZsy2Vf8ugjbze0PWLMIt7qDpMGeIjN2n Biu4DbS5/vUv1TSvWKgRSbg7iLgg1VqTplcbwaMyQoi73nbRuFDvriKeuiqW+NqAcBCn PQGYmO252/puBu78G1CUzQu70wT6A63jZzzu+vMSurg7t/NBG9pzujjMOo7Qyg4Tz7pW xe3umKVNlj+gKqHoJA0dmJKRdaUZtWzztPnpMzS8KZy2xWkqK1DDJBt7qLxvTfvX3EZx EiEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738681532; x=1739286332; h=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=OmmC015QrMlGvxSMXju2uqzozGJhow2yVM1ePz8K/rE=; b=K/J3WBe6H1eJwlGqfgljq2UpMLr91jJgSkN7OqTGgofDrTg36NW9pSGMSl0/l5rdsI PktaiikbUh20P/DWcsURqhx3Z6552L5z901xh1hYixgT+nk6ePqffI7TSJ3zbP02k3af lfwBILtCdr58LmaWgWa5scLmPMvMtYbvPDhJxmGjW1UYJhuzR85f2Rcv7gS3oUeVYXho QcsoChGqpmGGg4ZUcwody/u09UYtGB96ZKW4+XRDgT4jsUfcKBz6Fc827NkOzs3IWlV5 uKZO4cidECw+r/NfemC0Upc23/ikxwaNPE/akX/agkVagnkIit3ypuTLdtp7vwrr26zs t48w== X-Gm-Message-State: AOJu0YxfwbuMkWJ1MjqaTt2DThsGwjhwZpyEu2qhI0nHN4CTwHms1t41 h5G4uDfivole2vFVKeg8DgFN+BviZch4vDdUzF3ycK3GsNxvkB8/xACUiw0f3NgLhgz7E0z/Cd2 sdQpfka0sl6AiKtPTG0WnAX5psoK0JA== X-Gm-Gg: ASbGnctT6Fn9i8enzldIGNIEwcjYYTKDJtBflREdqNf55CFi36gIHKqp+g1xtBDUhvE hIkFvdfPha2fE1aHyda0uLsih+jT1y5jSj2vhIsyeMyfrVyNLVGgI0SbN245IEttBEJjXc2+02A == X-Google-Smtp-Source: AGHT+IH7q//FFf19UfDxW/UhyeA5eUjxmOx9bZsTCrt5UnGFG+rX8oGtY9IWbjCtTYYcySzWOJA0064FeP4o4jXiPXI= X-Received: by 2002:a05:6870:56a4:b0:29e:671b:6019 with SMTP id 586e51a60fabf-2b32f284055mr17237545fac.31.1738681532200; Tue, 04 Feb 2025 07:05:32 -0800 (PST) MIME-Version: 1.0 References: <4e7a338-c7d3-e944-20bd-a6e346e175c7@appl-ecosys.com> In-Reply-To: From: Ron Johnson Date: Tue, 4 Feb 2025 10:05:20 -0500 X-Gm-Features: AWEUYZnm-BtXGreasWCVfGp5bRN7z31eYrNvHUEbM0X1nt7bJM7z7ZhpGJF17x8 Message-ID: Subject: Re: Lookup tables To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000001abedf062d525786" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001abedf062d525786 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 4, 2025 at 9:59=E2=80=AFAM David G. Johnston wrote: > On Tuesday, February 4, 2025, Ron Johnson wrote= : > >> On Tue, Feb 4, 2025 at 9:41=E2=80=AFAM David G. Johnston < >> david.g.johnston@gmail.com> wrote: >> >>> On Tuesday, February 4, 2025, Rich Shepard >>> wrote: >>> >>>> Should lookup tables have a numeric FK column as well as the >>>> description column? >>>> >>>> If so, how should I add an FK to the two lookup tables in my database? >>>> >>> >>> Most do (have a surrogate PK) since it removes cascading updates >>> >> >> How does a synthetic PK "remove cascading updates"? Doesn't the decisio= n >> on whether or not to cascade update depend on the ON UPDATE CASCADE clau= se >> of the FK definition? >> >> > People don=E2=80=99t change synthetic PKs so updates never have to happen= on the > FK side. Labels do get changed, in which case you have to update the FK > label side. > That's the argument between a synthetic PK and a natural PK. (Everywhere I've seen natural PK used -- that was 25 years ago -- you didn't use the whole text of the description of the PK, you used a code, like 'HRLY' for hourly wage employees and 'SLRY' for salaried employees. Then, HRLY or SLRY would go in the t_employee table income_type VARCHAR(4) column, referencing a lookup table. --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000001abedf062d525786 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Feb 4, 2025 at 9:59=E2=80=AFAM Da= vid G. Johnston <david.g.j= ohnston@gmail.com> wrote:
On Tuesday, F= ebruary 4, 2025, Ron Johnson <ronljohnsonjr@gmail.com> wrote:
On Tu= e, Feb 4, 2025 at 9:41=E2=80=AFAM David G. Johnston <david.g.johnston@gmail.com= > wrote:
On Tuesday, February 4, 2025, Rich Shepard <rshepard@appl-ecosys= .com> wrote:
Sh= ould lookup tables have a numeric FK column as well as the description colu= mn?

If so, how should I add an FK to the two lookup tables in my database?

Most do (have a surrogate PK) since it rem= oves cascading updates
=C2=A0
How do= es a synthetic PK "remove cascading updates"?=C2=A0 Doesn't t= he decision on whether or not to cascade update depend on the ON UPDATE CAS= CADE clause of the FK definition?


People don=E2=80=99t change synthetic PKs so updates neve= r have to happen on the FK side.=C2=A0 Labels do get changed, in which case= you have to update the FK label side.

That's the argument between a synthetic PK and a nat= ural PK.=C2=A0 (Everywhere I've seen natural PK used -- that was 25 yea= rs ago -- you didn't use the whole text of the description of the PK, y= ou used a code,=C2=A0like 'HRLY' for hourly wage employees=C2=A0and= 'SLRY' for salaried employees. Then, HRLY or SLRY=C2=A0would go in= the t_employee table income_type VARCHAR(4) column, referencing a lookup t= able.

-- =
Death to &l= t;Redacted>, and butter sauce.
Don't boil me, I'm still aliv= e.
<Redacted> lobster!
--0000000000001abedf062d525786--