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

Поиск
Список
Период
Сортировка
От Greg Sabino Mullane
Тема Re: How do I copy part of table from db1 to db2 (and rename the columns)?
Дата
Msg-id 4dbd178fd48b28d5ad56837a0d87fc2a@biglumber.com
обсуждение исходный текст
Ответ на How do I copy part of table from db1 to db2 (and rename the columns)?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
Список 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 по дате отправления:

Предыдущее
От: Zac
Дата:
Сообщение: Re: psql commandline
Следующее
От: Kenneth Gonsalves
Дата:
Сообщение: Re: psql commandline