Copy table structure only (PostgreSQL)

From ben.goodacre.name/tech

Jump to: navigation, search

Create a copy of a table but with no data inside it:

create table table2 ( like table1 INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES );

OR with older versions use a piped pg_dump output with sed:

pg_dump -t table1 | sed 's/table1/tabble2/g' | psql
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox