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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Unable to use INSERT ... RETURNING with column from other table
Дата
Msg-id 15480.1508900684@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [SQL] Unable to use INSERT ... RETURNING with column from other table  (Peter Geoghegan <pg@bowt.ie>)
Ответы Re: [SQL] Unable to use INSERT ... RETURNING with column fromother table  (Andreas Joseph Krogh <andreas@visena.com>)
Список pgsql-sql
Peter Geoghegan <pg@bowt.ie> writes:
> As David says, you could use multiple CTEs for this.

Yeah.  The SELECT portion of the query, so far as the outer INSERT
is concerned, is just a black box that yields some column values to
be inserted.  We could wish that the INSERT's RETURNING clause
could examine additional column values that are available inside that
subquery, but I'm afraid that there are insurmountable semantic problems.
In particular, DISTINCT seems to break that entirely --- consider

insert into foo(id, name) select distinct 3, f.name from foo f where ...
returning id, f.id;

We can't just add "f.id" to the set of columns returned by the SELECT
part without changing the semantics of the DISTINCT.  Or if we ignore
that (acting like it was DISTINCT ON (3, f.name)) then we get an
underdetermined value of f.id, which doesn't seem appetizing either.
        regards, tom lane


-- 
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 по дате отправления:

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: Re: [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