How to clone a table so that primay and foreign keys remain

Поиск
Список
Период
Сортировка
От Andrus
Тема How to clone a table so that primay and foreign keys remain
Дата
Msg-id ek6d9u$1pn1$1@news.hub.org
обсуждение исходный текст
Ответы Re: How to clone a table so that primay and foreign keys remain  ("William Leite Araújo" <william.bh@gmail.com>)
Список pgsql-general
I need to clone a schema in a database programmatically.
Using pg_dump.exe to dump chema in plain text, then rename old schema and
after that
use pg_restore.exe to restore schema is slow since I need to clone data only
in some smaller tables.
Most of tables should be cloned without data.

To start this I think I need to clone all schema tables first.

How to create copy of table so that  primary keys and foreign keys
relationships remain ?

I tried

CREATE TABLE clone AS SELECT * FROM original

But this creates plain table.

Any idea ?
Or where to find sample (simpler that pgAdmin or pg_dump source code) which
re-constructs statements to create primary and foreign keys ?

Andrus.



В списке pgsql-general по дате отправления:

Предыдущее
От: "Andrus"
Дата:
Сообщение: more than one row returned by a subquery used as an expression
Следующее
От: "Andrus"
Дата:
Сообщение: Re: How to make a copy of schema