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.98.2) (envelope-from ) id 1xCQEd-00000003mqa-3TfM for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Oct 2026 23:30:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xCQEa-00000009KFy-3Gy1 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Oct 2026 23:30:40 +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.98.2) (envelope-from ) id 1xCQEa-00000009KFp-1lkl for pgsql-hackers@lists.postgresql.org; Thu, 01 Oct 2026 23:30:40 +0000 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xCQEY-00000002GvI-1AUo for pgsql-hackers@postgresql.org; Thu, 01 Oct 2026 23:30:39 +0000 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-4887840c529so2433878f8f.1 for ; Thu, 01 Oct 2026 16:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790897436; x=1791502236; darn=postgresql.org; h=in-reply-to:references:mime-version:content-transfer-encoding:cc :subject:to:from:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=JcB21e95asl9zmvbxkHz31mzLB+jlPPP2CXA9dmIo0s=; b=mL9Df879BvHXOELj+Ii6t7xoAwuH/J6uMNDqRJzTM/GDoyh94JQvymfGxLFCdIm5ya /T2JTgvmXTd/NouC8eDMoMueTKQp/2tlnP+neU6zpX+A5jcJwU8zVKGMKGGaaT6nJl12 jPMa30x27OTXWehLvuTeGpYzgMgGqwwkhkoW9YutZBq/oJ4+WGtQSf0GKAbw/ckIMkkE HVjSnwz1HwWSYf2cl+Zp7vrR7SU5Z0uZY5FzVBtBjb1/+lSCg2VpETnRcCnyC9TcQi9k 3DdFU16R1QJU09D+gHXxxvI33DfrFkY9oNRG5uyodeFDBoYsN05gz4e8Wgmnz8o5JgUq EWkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790897436; x=1791502236; h=in-reply-to:references:mime-version:content-transfer-encoding:cc :subject:to:from:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JcB21e95asl9zmvbxkHz31mzLB+jlPPP2CXA9dmIo0s=; b=e8BS9TRTFLUcM7jUXuCOuXC9GQZCm133zn6Ru6bf+2EbXHlBIOVFlaI8qxPRbpNJoT ijl97x0qzvW3OLh0Fef+mTuaSuHpT9LfhdDnxIbiMZB/W0wSBNdck46Wft6HM8WO+ZD+ qp11gxSd45bVlY6GLQWiTdJckkCe+sp0VuhCrNK1iDpRyNvmWN4FjfsbA4pLQMLWIdul WTAtd4U9Q7+sOrVsYyi2qwIimlZkfm40lBUlAyJ/Avl1Sswt32gFA6ZY4+/9VCqLmZOI nDUDHDP9ZvaazmQYSaML4qRo5xZS2dsKzzN9u8F5oXSXwQwTdK/d6SFekM9IwtdXh//4 lAkw== X-Gm-Message-State: AFuF++m8YkCqAGg6YWw9dfaSbZDB/6MrQ99k1E4KJzM81nHUBf/2PSPQ L8Qh612QuINtEquSXeG79tNRU/OPZ0ZGGVVj9OR1NhHAgy2stf0tIL7A X-Gm-Gg: AYBFou05aegYfVV0TQIdEA8MCAElDzAl5EOmSVaC96UmVrCwnQYH7Pm1PMEC2av9/tn bd9PhilxMszXWoixlDkvNrZBFpHIfbnR/Z6Kh8Cf3Nt2LCItjWjAkfnhZ9WW6TG+TJjWDzHLT9p 9HqoHxkt6f0fNYOMz4/vjZd9OWxyU6e7/PXfa5BRc8QHL4+hrLUaRfKEbJx6oebDvcQPHe5jkTA NJwXoFME0jGzl+X94TUI+q7J+oWKqGPgqro/DRCgeTTqXgn8UHhljW0MGH6yQyuRfhoae3TCqGm TMYlzk65m6N+HdOhDZKARA97H+OAeNbUImksGC2jpRKEgF/+Kt1tbjPfNbgTHaBFDOCZ4zuzMY6 t38rQztMdkFSg55ySaLte7apUObIWYvPIdvd2LvZx752lM0R36A02WmrqBWaKTk517b9+Sr3sJ0 KR5T3HJDJtOeM1SF8iOXF32ghySzRSSA4msIklJ79tLvVHLPXY5eXhox2a4FTFVfBWOo+n4br6k 4vXFksCRTwVlWBBNw== X-Received: by 2002:a05:600c:4e93:b0:4a0:1ef1:b62b with SMTP id 5b1f17b1804b1-4a02754f71emr18641485e9.10.1790897436014; Thu, 01 Oct 2026 16:30:36 -0700 (PDT) Received: from localhost ([2a02:169:191:0:451b:8d6d:91ef:3e90]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a027698f13sm27263325e9.1.2026.10.01.16.30.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Oct 2026 16:30:35 -0700 (PDT) Content-Type: text/plain; charset=UTF-8 Date: Fri, 02 Oct 2026 01:30:35 +0200 Message-Id: From: "Alberto Piai" To: "Laurenz Albe" , "Alberto Piai" , "Matthias van de Meent" , =?utf-8?q?=C3=81lvaro_Herrera?= Subject: Re: Adding a stored generated column without long-lived locks Cc: Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-Mailer: aerc 0.21.0 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu Sep 24, 2026 at 12:47 PM CEST, Laurenz Albe wrote: > On Thu, 2026-09-24 at 00:19 +0200, Alberto Piai wrote: >> I find Matthias' proposal of exposing a function to check image equality >> very compelling for the purpose of this patch: besides fixing this >> problem, it would also make the command usable for data types which >> don't define =3D (json), as well as those which don't (can't?) define >> equalimage()... jsonb, numeric but also tsvector and PostGIS geometry. > > True, "tsvector" is limiting; I can see people wanting that for > generated columns. I spent some time thinking about the situation, especially about whether the incoherence between the backfilled value and the result of thegenerator expression actually matters in practice. I am acutely aware that the example I reported earlier is somewhat... artificial. However, the fact that any rewrite operation which causes the expression to be recomputed would silently change the stored value (update a =3D a) really makes me want to treat this like a soundness issue in my patch. (Not to mention the broken pg_restore). So I see only a few ways forward: - drop this patch, which would be too bad because it does address an operational pain point - continue with IS NOT DISTINCT FROM, but restrict it to work with types which implement BTEQUALIMAGE_PROC. This would exclude useful types like jsonb, tsvector and geometry. (Aside regarding geometry: I never had the chance to work with PostGIS, but at a quick glance it seems to store a lot of information in typmod. It would definitely be wrong to implement equalimage. But there seems to be so much in there that I wonder whether it would not be very difficult for a user trying to backfill the column to do so in a way that it would satisfy a stricter image-equality constraint. I might very well be misreading all of this, though.) - work on exposing image equality as proposed by Matthias' pg_datum_image_equal(), and require that for the constraint (we could optionally allow IS NOT DISTINCT FROM for types which implement equalimage, but I find the function as simple to use. Since this is an extremely ad-hoc constraint created just for the purpose of a migration, I'd go for function-only) The notion of image equality already is somewhat exposed to the user through *=3D (record_image_eq). I wonder what could be the downsides of also exposing it for a single Datum. For the purpose of this alter table command, one concern could be that it's "too difficult" to produce values satisfying the stricter constraint when backfilling (see concerns about gemoetry above). But for the use cases I would use it for, I'd write the backfilling code to derive the value from the row, using the exact same expression I just used for the constraint. And if I failed to do so, then I'd get a pretty clear constraint failure. I'll add my review and this use case to the other thread, but in the meantime I thought I could already post this, even if it contains more open thoughts and questions than a concrete proposal. Regards, Alberto --=20 Alberto Piai Sensational AG Z=C3=BCrich, Switzerland