Re: Column names for INSERT with query

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Column names for INSERT with query
Дата
Msg-id 1377268367186-5768388.post@n5.nabble.com
обсуждение исходный текст
Ответ на Column names for INSERT with query  (Robert James <srobertjames@gmail.com>)
Список pgsql-general
Robert James wrote
> I would like to:
>
> INSERT INTO t
> SELECT * FROM r, (x + y) AS field3
>
> How do I correlate the names of the fields? That is, how do I indicate
> which fields from r or field3 should be inserted into the right
> columns in t?

Already answered but I'll add that as written, assuming there are enough
columns present, the syntax shown will work and do a pair-wise matching of
columns in the order defined in the catalog for table "t".  You can view
that order by simply issuing a "SELECT * FROM t".  If you know the order of
"t" you can simply explode the "SELECT * FROM r, (x+y)" into an explicit
column-list that has the same ordering as "t".  There are limitations,
mainly as relates to default values, but for a table "t" with a large number
of columns it can be considerably less verbose/tedious to write.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Column-names-for-INSERT-with-query-tp5768334p5768388.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: Osvaldo Kussama
Дата:
Сообщение: Re: numeric to ipv6 inet
Следующее
От: "Hall, Samuel L (Sam)"
Дата:
Сообщение: Update quey