User Tools

Site Tools


copy_table_to_another_schema

Copy Table to another Schema

The SQL Way

CREATE TABLE new_schema.my_table  (LIKE other_schema.my_table INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING CONSTRAINTS);

The INCLUDING keywords are PostgreSQL specific. Regardless of the INCLUDING CONSTRAINTS keywords foreign constraints will not be copied/created.

To copy the contents just use an INSERT statement like this:

INSERT INTO new_schema.my_table SELECT * FROM other_schema.my_table;
copy_table_to_another_schema.txt · Last modified: 2013/10/02 07:12 by mihael