referencing other INSERT VALUES columns inside the insert

From: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: referencing other INSERT VALUES columns inside the insert
Date: 2015-11-16 10:30:18
Message-ID: CAEzk6fcL53X6bb1T4cq4Q5OH2cBN5nLy60KhH_S3HfYcptA=Hg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I know that this is something that can't be done...

CREATE TABLE test (c1 int default 0, c2 int default 0, c3 int default 0);
INSERT INTO test (c1, c2, c3) VALUES (3, 7, c1 * c2);

Is there a known trick to work around it (so that the values inserted into
c1 and c2 is referenced back to c3), other than (obviously!) copying the
literal values into the VALUES string?

To be clear, the SQL is generated dynamically based on data, so I can't
just create a view for the calculated column (it won't always be
calculated!).

Thanks!

Geoff

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sachin Srivastava 2015-11-16 10:31:42 DB_link connection
Previous Message Albe Laurenz 2015-11-16 08:43:36 Re: can postgres run well on NFS mounted partitions?