Page 1 of 1
[PostgreSQL] Insert values from table a to table b?
Posted: Wed Aug 29, 2007 10:32 am
by Jenk
Hi,
I've got two tables; and I would like to perform:
Code: Select all
INSERT INTO tableA (tableA.col1, tableA.col2) VALUES ((SELECT tableB.col1, tableB.col2 FROM tableB));
But that doesn't work (hence the post) and I've googled just about everything I can think of. Does anyone have any idea?
Thanks.
Re: [PostgreSQL] Insert values from table a to table b?
Posted: Wed Aug 29, 2007 10:37 am
by timvw
Afaik, this should work (don't have pgsql around here)
Code: Select all
INSERT INTO a (col1, col2)
SELECT colX, colY FROM b;
Anyway, the precise syntax is in:
http://www.postgresql.org/docs/7.4/inte ... nsert.html (They only provide an example where they asume the 'default' column/value order)
Posted: Wed Aug 29, 2007 10:52 am
by Jenk
Would you believe me if I told you I've already read that page? How on god's green Earth did I miss that?

Posted: Wed Aug 29, 2007 3:37 pm
by timvw
Jenk wrote:Would you believe me if I told you I've already read that page? How on god's green Earth did I miss that?

Well, the first three times i looked at it, i didn't spot it either.. Imho a good indication that their documentation needs improvements
