Re: BUG #17970: FEATURE REQUEST-allow re-adding GENERATED ALWAYS AS constraint to existing columns after removing it

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgp(at)gmx(dot)it, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17970: FEATURE REQUEST-allow re-adding GENERATED ALWAYS AS constraint to existing columns after removing it
Date: 2023-06-13 14:45:51
Message-ID: CAKFQuwbPggYTMKWtwPeoZ==dfp0jYjMnhKtM=y70-w95XduG4Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jun 13, 2023 at 7:21 AM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 17970
> Logged by: PGP
> Email address: pgp(at)gmx(dot)it
> PostgreSQL version: 15.3
> Operating system: Linux
> Description:
>
>
The bug reporting form is not an appropriate place to discuss feature
requests. Please subscribe to the -general list if you wish to start and
partake in such discusssions.

But the reverse (i.e. re-adding the "GENERATED ALWAYS AS .. STORED" part to
> an existing column) is not possible.
> I think this is a contradiction, because, by modifying the underlying
> function, I am able to insert incoherent values in the generated column,
> so,
> since this is allowed, it should be possible as well to add again this kind
> of constraint, after temporarily dropping it (for example, for doing a bulk
> insert via COPY command, in the cases when generating the transformed_id
> values outside the db is more performant than generating them automatically
> within the insert statement).
>

I am doubtful any implementation of this feature is going to avoid
recomputing the generated column value for every existing row. I agree
that the syntax seems to be a missing feature. But apparently it wasn't
added for some reason and I see little true benefit to the feature itself.

Also, you are not allowed to modify the underlying function such that it
produces different values now for inputs than it did before. Sure, the
system is incapable of enforcing this rule, but it is well documented (see
the definition of immutable) and any consequences for violating the rule
are the fault of the admin, not the system.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-06-13 15:12:51 Re: BUG #17970: FEATURE REQUEST-allow re-adding GENERATED ALWAYS AS constraint to existing columns after removing it
Previous Message PG Bug reporting form 2023-06-13 13:45:55 BUG #17970: FEATURE REQUEST-allow re-adding GENERATED ALWAYS AS constraint to existing columns after removing it