Unable to use INSERT ... RETURNING with column from other table

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Unable to use INSERT ... RETURNING with column from other table
Date: 2017-10-24 22:04:04
Message-ID: VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi.
 
I'm having this schema:
 
create table foo( id integer PRIMARY KEY, name varchar not null ); insert into
foo(id,name) values(1, 'one'), (2, 'two'); insert into foo(id, name) select 3,
f.namefrom foo f where f.id = 1 returning id, f.id; ERROR:  missing FROM-clause
entry for table "f" LINE 1: ...lect 3, f.name from foo f where f.id = 1
returning id, f.id;
I'd like to return f.id and the inserted id, is this possible?
 
I want this because I'm hoping to use this in a CTE where other selects from
this CTE will use this extra column.
 
Thanks.
 
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Geoghegan 2017-10-24 22:06:59 Re: Unable to use INSERT ... RETURNING with column from other table
Previous Message Klaus Kaisersberger 2017-10-17 20:49:01 Re: How to get the list of tables with encrypted columns