Re: Copying data from one table to another - how to specify fields?

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Copying data from one table to another - how to specify fields?
Date: 2011-03-09 14:12:27
Message-ID: 20110309141226.GJ32629@shinkuro.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 09, 2011 at 02:47:46PM +0100, Alexander Farber wrote:
> I would like to copy these fields from one table:
>
> select user_id, username, user_email, user_regdate, user_lastvisit
> from phpbb_users where user_id > 50;
>
> into the other (already existing) table:
>
> select uid, name, mail, created, access from drupal_users;
>

INSERT INTO drupal users (uid, name, mail, created, access)
SELECT user_id, username, user_email, user_regdate, user_lastvist
FROM phpbb_users where user_id > 50;

This is sort of like an example on
http://www.postgresql.org/docs/9.0/interactive/sql-insert.html, but
that example uses SELCT *. Perhaps an additional example would have
helped? (This is basic SQL, though, and I'm not sure the keyword
manual is the best place for such an example.)

A

--
Andrew Sullivan
ajs(at)crankycanuck(dot)ca

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2011-03-09 14:21:23 Re: Copying data from one table to another - how to specify fields?
Previous Message Vibhor Kumar 2011-03-09 14:10:06 Re: FW: backup using pg_dump postgreSQL 8.3.8