Re: [SQL] Unable to use INSERT ... RETURNING with column from other table

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Re: [SQL] Unable to use INSERT ... RETURNING with column from other table
Дата
Msg-id CAH2-Wzm4Qss48XbhWEDuLTcnFCi7QzKWtiNwYBk1LurcC9CdKQ@mail.gmail.com
обсуждение исходный текст
Ответ на [SQL] Unable to use INSERT ... RETURNING with column from other table  (Andreas Joseph Krogh <andreas@visena.com>)
Ответы Re: [SQL] Unable to use INSERT ... RETURNING with column fromother table  (Andreas Joseph Krogh <andreas@visena.com>)
Список pgsql-sql
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.

-- 
Peter Geoghegan


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

В списке pgsql-sql по дате отправления:

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: [SQL] Unable to use INSERT ... RETURNING with column from other table
Следующее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: [SQL] Unable to use INSERT ... RETURNING with column fromother table