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 1tfmoF-00543R-HL for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2025 21:19:48 +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 1tfmoE-001Grs-37 for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2025 21:19:46 +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 1tfmoD-001Grk-Mq for pgsql-general@lists.postgresql.org; Wed, 05 Feb 2025 21:19:45 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tfmoB-003bxB-0Z for pgsql-general@lists.postgresql.org; Wed, 05 Feb 2025 21:19:45 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-aaec111762bso65396066b.2 for ; Wed, 05 Feb 2025 13:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kleczek.org; s=google; t=1738790382; x=1739395182; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=InU4yLCtiRXQyb/Vp2rYz4yfpAYhacDz2D31wl1Xb5k=; b=EZQeADJyDIfrMFuanLScDBZ7bsEE487Z5T8A14kGZbqullodg30wSaEPNwooQNaO+6 7c27ELLsjKi/cQO06RATsQenTp9X3s2XRe+XdMcW/dLF7+LGoVylimu6e1ScZDBiSMet 57QbFYnZNIEOTfX9j00x4neUr8nNLG+2lXO4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738790382; x=1739395182; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=InU4yLCtiRXQyb/Vp2rYz4yfpAYhacDz2D31wl1Xb5k=; b=P0UCk1I4nls08P8Y0X5XuoFg7i/0TOA7/F9/GCgfE3ZKIFYWSre3bI4TerTEr16Ukt Xs0CXz2dvMgiZwvEY0iRoauALfANGX3VeNMZSAig7ZaDftGe8kZDgkrhkaIYkUmVWnWT C/Zi3k2IwPd8nSorzYMswFRXTgr7UEZWvmMkk+2Nq+KHJ47VEPWLJk5E1CUMFKpSaxjG MZkbKYqMT3luXtDAb926RvA8FDqoFTFC9lfNixE6GkZgz4Ip/g9a9aQHg5fgevaYxEef /mxPYobxshJwAZ05o4+EQwtyf9ewVHkW0sAEJmwf29KpmUwttEqO6VKz+eWuYbE3DxM0 +EBQ== X-Gm-Message-State: AOJu0YyLsFs2wLYx5gnOnHu/okhr20DCT4WgFb/ntTrmPBjWw2Lvd+PV qTabja/84w901aGee2MUNzEKlBF2ArM1VyvSiZlizIi1mrN823MMJ1vLM4AkB8tbVimv5dX/kCf nXN8= X-Gm-Gg: ASbGnctfT0lGCbXkn6bVO7pw6PzLb9z8WOh7FaLZF9Jmqd3PW396BjH4DIjYQ3kwJEj gI34Jrfq0LbzSEFO+OQ4+ioN6jxav9i3wdZG1glEBfU3l/OyHYLQ00wyyIB6D4jw/0CuGpj3p7J HoUiQorrqjwDGo45P+hq6+MsN8Vt/QYbRbY004J+gf+H2JtunTXQQ89EhLpyIbBmHoH8HVij5y2 82o+FUUGgMaw3T2A4v5hfO4rWFWuVI8iAwdelnpXKXR3zLKHvBrFyTV9Rf/nr4ANkj/lKHcO6k/ RnX+opbSg6ZkAPauDgA03pgYA9Y1J5NQeGexJNUj3LE= X-Google-Smtp-Source: AGHT+IH9IeeaQsJGrMyDOE8vLio0kf2czMOIdlfUaTJ3YxQZ6Bf0xozs9rYlY6skQZAsuLxSi3Q6uA== X-Received: by 2002:a17:906:1915:b0:ab7:6c4b:796a with SMTP id a640c23a62f3a-ab76c4b8378mr156807466b.39.1738790382289; Wed, 05 Feb 2025 13:19:42 -0800 (PST) Received: from smtpclient.apple (b15.kleczek.org. [185.20.172.182]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7656d5d5asm128454966b.48.2025.02.05.13.19.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Feb 2025 13:19:41 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.300.87.4.3\)) Subject: Re: Lookup tables From: =?utf-8?Q?Micha=C5=82_K=C5=82eczek?= In-Reply-To: <8a118426-7b8a-4d8b-a22b-3bdee2e5e187@gelassene-pferde.biz> Date: Wed, 5 Feb 2025 22:19:30 +0100 Cc: pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: <878194FA-E9F8-4688-9904-06B8D2A4DD5C@kleczek.org> References: <628D4022-5365-4D00-810B-10349A90874A@kleczek.org> <64603f36-b6d5-469b-8d6d-30376842241b@gelassene-pferde.biz> <3A08C6E4-8B03-4D24-BAA7-53860A66C1AF@kleczek.org> <8a118426-7b8a-4d8b-a22b-3bdee2e5e187@gelassene-pferde.biz> To: Thiemo Kellner X-Mailer: Apple Mail (2.3826.300.87.4.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 5 Feb 2025, at 21:33, Thiemo Kellner = wrote: >=20 >=20 > El 05-02-25 a las 13:55, Micha=C5=82 K=C5=82eczek escribi=C3=B3: >>> A) Your release changed the sementics of the record 3. It's meaning = changed. I cannot recommend doing that. >> That=E2=80=99s what using natural keys and FK=E2=80=99s 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=E2=80=99s 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. = Y But you can guarantee that if you change the value of the key after the = user displays it - the user will get an error on submission (whereas = with the surrogate key it would happily proceed without user noticing). > ou 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. How so? The user is going to get FK violation - you do not need any = downtime to make sure users don=E2=80=99t submit wrong values. >>> 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. You can also simply disallow updates with FK constraint eliminating = risk. > 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=C3=9CN, VERDE or AS=C3=A9LDHK()*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). And why do you think unconstrained updating of business key is a good = thing? You must implement rules governing what can and what cannot be changed = *somewhere* - not doing it in the database means you have to do it in = applications. Anyway - let=E2=80=99s agree to disagree :) =E2=80=94 Michal=