pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Raynsford <co+org.postgresql@io7m.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Column value derived from generated column in INSERT?
Date: Wed, 19 Oct 2022 19:30:57 +0000
Message-ID: <20221019193057.39aff1c1@sunflower.int.arc7.info> (raw)
In-Reply-To: <CAKFQuwZpq-hZ-zBN8KhzF3Ke3bheHHpp_f=tEkH30+JTXtaMsg@mail.gmail.com>
References: <20221019173225.53d939f2@sunflower.int.arc7.info>
	<CAKFQuwZpq-hZ-zBN8KhzF3Ke3bheHHpp_f=tEkH30+JTXtaMsg@mail.gmail.com>

On 2022-10-19T11:58:07 -0700
"David G. Johnston" <david.g.johnston@gmail.com> wrote:

> On Wed, Oct 19, 2022 at 10:36 AM Mark Raynsford <co+org.postgresql@io7m.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."
> 

Hello!

Just want to confirm that I wasn't misunderstood. The documentation in
CREATE TABLE has the sentence you quoted above, and unless I'm
misunderstanding that's saying that the expression used to generate
values in GENERATED (ALWAYS AS) columns can't refer to 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.

If that's not doable, that's fine, I just want to be sure. :)

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






view thread (9+ messages)  latest in thread

Message-ID: <20221019193057.39aff1c1@sunflower.int.arc7.info>
Permalink:  ../20221019193057.39aff1c1@sunflower.int.arc7.info/
Also on:    postgresql.org/message-id/20221019193057.39aff1c1@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, david.g.johnston@gmail.com
  Subject: Re: Column value derived from generated column in INSERT?
  In-Reply-To: <20221019193057.39aff1c1@sunflower.int.arc7.info>
  References: <20221019173225.53d939f2@sunflower.int.arc7.info> <CAKFQuwZpq-hZ-zBN8KhzF3Ke3bheHHpp_f=tEkH30+JTXtaMsg@mail.gmail.com> <20221019193057.39aff1c1@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