Re: Adding a stored generated column without long-lived locks

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: Re: Adding a stored generated column without long-lived locks
Date: 2026-09-01 04:58:57
Message-ID: ec11199f39ad09c8561c1768b8626a9d76985cf8.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 2026-08-31 at 20:41 +0200, Alberto Piai wrote:
> I liked the = form too (but: there is a "but" coming later :)), I always
> looked at this from the perspective of a user who is intentionally
> running through these steps to perform a very specific migration.
> Assuming they don't make mistakes (or the expression is not nullable, as
> in the simple case of "b = a + 1" where the referenced a is NOT NULL), =
> works fine.
>
> The problem is that it's relatively easy to make a mistake (or a
> malicious user could take advantage of it) whenever the expression is
> nullable. In that case, a row could be added to the table that still
> satisfies the constraint (since CHECK constraints are satisfied when the
> expression evaluates to NULL), the alter table would happily run
> through, and the db would be left in an inconsistent state.
>
> In the case above of "b = a + 1", if a is nullable, b is NOT NULL and a
> row (a, b) with values (null, 42) is inserted, rewriting operations like
> update ... set a = a, or pg_dump/pg_restore would fail.

Embarrassing - I should have seen that during my review.

You are right, it's best to forget about check constraints with = here.

Yours,
Laurenz Albe

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Lakhin 2026-09-01 05:00:00 Re: Changing the state of data checksums in a running cluster
Previous Message Greg Burd 2026-09-01 04:41:20 Re: Speed up COPY FROM text/CSV parsing using SIMD