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: Re: Unable to use INSERT ... RETURNING with column from other table
Date: Wed, 25 Oct 2017 00:49:05 +0200 (CEST)
Message-ID: <VisenaEmail.5e.f9aed09bf35804e1.15f509189ac@tc7-visena> (raw)
In-Reply-To: <CAH2-Wzm4Qss48XbhWEDuLTcnFCi7QzKWtiNwYBk1LurcC9CdKQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

På onsdag 25. oktober 2017 kl. 00:06:59, skrev Peter Geoghegan <pg@bowt.ie 
<mailto:pg@bowt.ie>>:
On Tue, Oct 24, 2017 at 3:04 PM, Andreas Joseph Krogh
 <andreas@visena.com> wrote:
 > 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?

 It's possible on 9.5+. You need to assign the target table an alias
 using AS -- AS in not a noise word for INSERT (the grammar requires
 it).

 See the INSERT documentation.
 
I'm not sure how an alias for the target_table will help me here as I'm trying 
to return a value not being inserted?
f.id is not inserted, only columns matching f.id.
 
-- 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.5e.f9aed09bf35804e1.15f509189ac@tc7-visena>
Permalink:  ../VisenaEmail.5e.f9aed09bf35804e1.15f509189ac@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.5e.f9aed09bf35804e1.15f509189ac@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.5e.f9aed09bf35804e1.15f509189ac@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