pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Sabino Mullane <greg@turnstep.com>
To: pgsql-sql@postgresql.org
Subject: Re: How do I copy part of table from db1 to db2 (and rename the columns)?
Date: Wed, 31 Aug 2005 13:19:00 -0000
Message-ID: <4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com> (raw)
In-Reply-To: <1125482430.9456.6.camel@Panoramix>


-----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-----





view thread (11+ messages)  latest in thread

Message-ID: <4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com>
Permalink:  ../4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com/
Also on:    postgresql.org/message-id/4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: greg@turnstep.com
  Subject: Re: How do I copy part of table from db1 to db2 (and rename the columns)?
  In-Reply-To: <4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox