Re: Column value derived from generated column in INSERT?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Mark Raynsford <co+org(dot)postgresql(at)io7m(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Column value derived from generated column in INSERT?
Date: 2022-10-19 22:16:40
Message-ID: CAKFQuwYQgiFX8ZxKK8xFDiH=P-E3CAjWYbckbPpB7zAy+vgDuQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 19, 2022 at 12:34 PM Mark Raynsford <co+org(dot)postgresql(at)io7m(dot)com>
wrote:

> On 2022-10-19T11:58:07 -0700
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> > On Wed, Oct 19, 2022 at 10:36 AM Mark Raynsford <
> co+org(dot)postgresql(at)io7m(dot)com>
> > wrote:
> >
> > > insert into t (y) values (t.x * 2);
> > >
> > > I can think of various ways to do it with multiple statements, but a
> > > single statement would be preferable.
> > >
> > >
> > No, by extension of the documented constraint: "The generation expression
> > can refer to other columns in the table, but not other generated
> columns."
> >
>
>

> That's fine, but that's not what I was asking. In the table
> above, `x` is generated without references to other columns, but for
> the non-GENERATED `y` value, I want to refer to the value that `x` will
> have when I calculate a value for the `y` column in the INSERT
> statement.
>

Yes, I got that, but if another generated column cannot reference the
resultant computation of a generated column anything you write, which is by
definition computed before the generated column, is not going to be able to
see the result of the generated column either. There was at least some
hope for one generated depending upon another so the the expressions could
maybe be evaluated in sequence.

Thus, while the docs do not explicitly state the non-functionality it can
be inferred by what other non-functionality is stated.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Benedict Holland 2022-10-19 22:45:39 Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP
Previous Message Erik Wienhold 2022-10-19 22:09:09 Re: Column value derived from generated column in INSERT?