Search Postgresql Archives

Re: Column names for INSERT with query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux