|
Posted by Toby A Inkster on 01/30/08 16:26
Dan99 wrote:
> SELECT * INTO table2 FROM table
> This works well except for the fact that it doesnt copy anything but the
> data. For example any indexes, constraints, or triggers do not copy to
> the new table? How would I go about making an exact duplicate of a
> table?
CREATE TABLE foo (LIKE bar INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
INSERT INTO foo SELECT * FROM bar;
This will copy the table structure, data and constraints, but not indexes
or triggers. If you want to make sure that indexes and triggers are
copied, probably the best route is to use the pg_dump backup tool that
comes with PostgreSQL to dump the table in its entirety to a flat SQL
file, which can then be opened with a text editor to change the table name
and then restored.
I suggest continuing this discussion in comp.databases.postgresql.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 22:33.]
Looking Ahead to PHP 6
http://tobyinkster.co.uk/blog/2008/01/29/php6/
Navigation:
[Reply to this message]
|