Column value derived from generated column in INSERT?

From: Mark Raynsford <co+org(dot)postgresql(at)io7m(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Column value derived from generated column in INSERT?
Date: 2022-10-19 17:32:25
Message-ID: 20221019173225.53d939f2@sunflower.int.arc7.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

I'd like to be able to do something sort of analogous to this:

create table t (
x integer not null generated always as identity,
y integer not null
);

insert into t (y) values (t.x * 2);

In the real project, the "t.x * 2" expression is obviously something
a lot more complex, but I think it illustrates the point: I'd like to
be able to refer to the generated value of a column within the INSERT
statement that's going to cause it to be generated. Is there a way to
do this with a single statement right now?

I can think of various ways to do it with multiple statements, but a
single statement would be preferable.

--
Mark Raynsford | https://www.io7m.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-10-19 18:58:07 Re: Column value derived from generated column in INSERT?
Previous Message ertan.kucukoglu 2022-10-19 16:42:08 RE: Cannot restore windows dump on linux