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

From Greg Sabino Mullane
Subject Re: How do I copy part of table from db1 to db2 (and rename the columns)?
Date
Msg-id 4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com
Whole thread Raw
In response to How do I copy part of table from db1 to db2 (and rename the columns)?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
List 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@turnstep.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-----




pgsql-sql by date:

Previous
From: Zac
Date:
Subject: Re: psql commandline
Next
From: Kenneth Gonsalves
Date:
Subject: Re: psql commandline