[SQL] Unable to use INSERT ... RETURNING with column from other table - Mailing list pgsql-sql

From Andreas Joseph Krogh
Subject [SQL] Unable to use INSERT ... RETURNING with column from other table
Date
Msg-id VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena
Whole thread Raw
Responses Re: [SQL] Unable to use INSERT ... RETURNING with column from other table
List 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.name from 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

pgsql-sql by date:

Previous
From: Klaus Kaisersberger
Date:
Subject: Re: [SQL] How to get the list of tables with encrypted columns
Next
From: Peter Geoghegan
Date:
Subject: Re: [SQL] Unable to use INSERT ... RETURNING with column from other table