agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-sql@postgresql.org
Subject: Unable to use INSERT ... RETURNING with column from other table
Date: Wed, 25 Oct 2017 00:04:04 +0200 (CEST)
Message-ID: <VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com;
 <https://www.visena.com;

view thread (9+ messages)  latest in thread

Message-ID: <VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena>
Permalink:  ../VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas@visena.com
  Subject: Re: Unable to use INSERT ... RETURNING with column from other table
  In-Reply-To: <VisenaEmail.5d.3c4f083000723eca.15f50641885@tc7-visena>

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

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