Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
Jenk
- DevNet Master
- Posts: 3587
- Joined: Mon Sep 19, 2005 6:24 am
- Location: London
Post
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.
-
timvw
- DevNet Master
- Posts: 4897
- Joined: Mon Jan 19, 2004 11:11 pm
- Location: Leuven, Belgium
Post
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)
-
Jenk
- DevNet Master
- Posts: 3587
- Joined: Mon Sep 19, 2005 6:24 am
- Location: London
Post
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?

-
timvw
- DevNet Master
- Posts: 4897
- Joined: Mon Jan 19, 2004 11:11 pm
- Location: Leuven, Belgium
Post
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
