Re: How do I copy part of table from db1 to db2 (and rename the columns)?

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How do I copy part of table from db1 to db2 (and rename the columns)?
Date: 2005-08-31 13:19:00
Message-ID: 4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I want to copy several columns of a source table from db1 to db2, and
> create the target table and rename the columns in the process.

Ignoring the db part for now, you can do the first part of your request
like this:

CREATE TABLE mytable2 AS SELECT mycol AS newcolname, id, foo AS foo2
FROM mytable WHERE id > 100;

Then pg_dump -t mytable2 and pg_restore, as the rest of this thread indicates.

Note that you'll lose any triggers, indexes, etc. so only use this if
all you really want is the table. Otherwise, it's probably easiest to
pg_dump the whole database and then drop/rename columns in the new
database.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200508310915
https://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAkMVrhIACgkQvJuQZxSWSsg3ZwCgs5kG/5P+RFr315+v3ia0g+Tr
bAEAoKHfRhJYynxVqyo/U06WaSeDXh3s
=hZIK
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mavinakuli, Prasanna (STSD) 2005-08-31 14:12:24 PQexecParams-Problem
Previous Message Doug Bloebaum 2005-08-31 12:58:52 Re: About "ERROR: must be *superuser* to COPY to or from a file"

Browse pgsql-sql by date

  From Date Subject
Next Message Zac 2005-08-31 13:19:39 Re: psql commandline
Previous Message digit-x 2005-08-31 13:13:59 Re: psql commandline