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 1tfm5f-004yDs-Pl for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2025 20:33:44 +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 1tfm5e-000l4f-Lk for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2025 20:33:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tfm5e-000l4V-Ah for pgsql-general@lists.postgresql.org; Wed, 05 Feb 2025 20:33:42 +0000 Received: from sm-r-008-dus.org-dns.com ([84.19.1.236]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tfm5b-003b5u-2S for pgsql-general@lists.postgresql.org; Wed, 05 Feb 2025 20:33:41 +0000 Received: from smarthost-dus.org-dns.com (localhost [127.0.0.1]) by smarthost-dus.org-dns.com (Postfix) with ESMTP id 8A5A6A16E3 for ; Wed, 5 Feb 2025 21:33:39 +0100 (CET) Received: by smarthost-dus.org-dns.com (Postfix, from userid 1001) id 7CEB2A15E7; Wed, 5 Feb 2025 21:33:39 +0100 (CET) X-Spam-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_INFOUSMEBIZ, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from ha01s018.org-dns.com (ha01s018.org-dns.com [62.108.32.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smarthost-dus.org-dns.com (Postfix) with ESMTPS id F3FE6A16FC for ; Wed, 5 Feb 2025 21:33:38 +0100 (CET) Authentication-Results: ha01s018.org-dns.com; spf=pass (sender IP is 146.185.68.202) smtp.mailfrom=thiemo@gelassene-pferde.biz smtp.helo=[192.168.178.23] Received-SPF: pass (ha01s018.org-dns.com: connection is authenticated) Message-ID: <8a118426-7b8a-4d8b-a22b-3bdee2e5e187@gelassene-pferde.biz> Date: Wed, 5 Feb 2025 21:33:38 +0100 MIME-Version: 1.0 Subject: Re: Lookup tables To: pgsql-general References: <628D4022-5365-4D00-810B-10349A90874A@kleczek.org> <64603f36-b6d5-469b-8d6d-30376842241b@gelassene-pferde.biz> <3A08C6E4-8B03-4D24-BAA7-53860A66C1AF@kleczek.org> Content-Language: de-CH-frami, en-GB, it-CH, fr-CH, es-CL, es-ES From: Thiemo Kellner In-Reply-To: <3A08C6E4-8B03-4D24-BAA7-53860A66C1AF@kleczek.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-PPP-Message-ID: <173878761886.3424846.10138728774167101038@ha01s018.org-dns.com> X-PPP-Vhost: gelassene-pferde.biz X-POWERED-BY: wint.global - AV:CLEAN SPAM:OK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk El 05-02-25 a las 13:55, Michał Kłeczek escribió: >> A) Your release changed the sementics of the record 3. It's meaning changed. I cannot recommend doing that. > That’s what using natural keys and FK’s restricting their changes guarantee: no (accidental) changes to meaning of data. > Even with cascading updates you still have transactional semantics (ie. the user selects what’s on the screen or gets an error). Sorry, that is utter nonsense. You cannot ever guarantee an update does not mess up the semantics on the updated field, change the meaning. You would need a check constraint which in it turn needs to get set up where one can mess up things. >> B) If you absolutely must change the semantic, put your application into maintenance mode in which noone can select anything beforehand. > All this error prone hassle and downtime can be avoided with natural keys and guarantees that DBMS gives you. And I thought you would have denied the need of changing semantics above. And no, changing your natural keys semantically ALWAYS requires downtime to make sure you do not run into the race condition described above. >> If the maintenance would just correct the typo from GREE to GREEN, nothing would happen. Yor customer still ordered the lavishly green E-Bike her hear ever desired. > The question is: how do you _ensure_ that? Ensure, the update goes from GREE to GREEN? You cannot, simple as that. You just can minimize the risk by testing, testing, testing. But that holds equally true for the business key of a surrogate key table as natural key table. That's why the surrogate key is such an elegant construct. You can change business key of the record with id 3 from GREE to GREEN, VERT, GRÜN, VERDE or ASéLDHK()*NSLDFHP)(*Z . It keeps its meaning of the perception of the human eye of electromagnetic waves of the wavelength roughly between 495-570 nm (according to Wikipedia).