Re: Column names for INSERT with query - Mailing list pgsql-general

From David Johnston
Subject Re: Column names for INSERT with query
Date
Msg-id 1377268367186-5768388.post@n5.nabble.com
Whole thread Raw
In response to Column names for INSERT with query  (Robert James <srobertjames@gmail.com>)
List 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 by date:

Previous
From: Osvaldo Kussama
Date:
Subject: Re: numeric to ipv6 inet
Next
From: "Hall, Samuel L (Sam)"
Date:
Subject: Update quey