pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Raynsford <co+org.postgresql@io7m.com>
To: pgsql-general@lists.postgresql.org
Subject: Column value derived from generated column in INSERT?
Date: Wed, 19 Oct 2022 17:32:25 +0000
Message-ID: <20221019173225.53d939f2@sunflower.int.arc7.info> (raw)

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






view thread (9+ messages)  latest in thread

Message-ID: <20221019173225.53d939f2@sunflower.int.arc7.info>
Permalink:  ../20221019173225.53d939f2@sunflower.int.arc7.info/
Also on:    postgresql.org/message-id/20221019173225.53d939f2@sunflower.int.arc7.info

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: co+org.postgresql@io7m.com
  Subject: Re: Column value derived from generated column in INSERT?
  In-Reply-To: <20221019173225.53d939f2@sunflower.int.arc7.info>
  References: <20221019173225.53d939f2@sunflower.int.arc7.info>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox