Re: Bug / Unintentional Feature: non-immutable functions can be used for generated columns.

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shane Plesner <gebnar(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Bug / Unintentional Feature: non-immutable functions can be used for generated columns.
Date: 2022-10-01 18:54:36
Message-ID: CAKFQuwbg6OF0RntkAmK9SND+i5fYDV9XQEShJQ_eP0TeCqAcWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sat, Oct 1, 2022 at 8:27 AM Shane Plesner <gebnar(at)gmail(dot)com> wrote:

> Important preface: This "bug" turns out to enable functionality that is
> extremely useful. Please carefully consider how the usefulness of this can
> be retained when "fixing" the bug.
>
> No error or warning or behavioral problems occur if the function used to
> fill a generated column is replaced with a non-immutable version after it
> is assigned as the column generator.
>
>

> Discovered by Shane Plesner, by accident, about 10 minutes ago...
>

Discovered (in various incarnations) by many people over the years...

The documentation clearly states this is not a supported setup. In
particular it tends to break during dump/restore (though I think that
mostly happens for check constraints). It is unfortunate that the system
cannot simply prohibit the action and instead must rely upon documentation,
but that is how things are. Furthermore, if you lie to the system like in
your example, about your function being immutable when it actually is not,
the consequences are on you alone (i.e., we do not try to static analyze
the function body). That includes fixing any problems if you determine a
truly immutable function is buggy and thus needs to be changed to produce
the correct output which is different that prior output.

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2022-10-01 21:09:54 BUG #17626: Permission denied errors should list role as well as user
Previous Message Shane Plesner 2022-10-01 15:18:41 Bug / Unintentional Feature: non-immutable functions can be used for generated columns.