Help using SELECT INTO to make schema

Started by Robert Jamesover 16 years ago2 messagesgeneral
Jump to latest
#1Robert James
srobertjames@gmail.com

I'd like to SELECT INTO one table into another one. However, I'd like to do
two things that I don't know how to do using SELECT INTO:

1. Copy over the indexes and constraints of the first table into the second
2. Do SELECT INTO even if the second table already exists.

Is there anyway to do either one of those?

Failing that, is there a way to copy a table's schema - its columns,
indexes, and constraints - into a new (empty) table?

#2Jeff Davis
pgsql@j-davis.com
In reply to: Robert James (#1)
Re: Help using SELECT INTO to make schema

On Wed, 2009-07-22 at 18:15 -0400, Robert James wrote:

I'd like to SELECT INTO one table into another one. However, I'd like
to do two things that I don't know how to do using SELECT INTO:

1. Copy over the indexes and constraints of the first table into the
second

See: http://www.postgresql.org/docs/8.4/static/sql-createtable.html
LIKE parent_table [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS |
INDEXES } ]

2. Do SELECT INTO even if the second table already exists.

INSERT INTO foo ... SELECT

Regards,
Jeff Davis