Re: create table as vs. create table like - Mailing list pgsql-general

From Gregory Williamson
Subject Re: create table as vs. create table like
Date
Msg-id 8B319E5A30FF4A48BE7EEAAF609DB233021F383D@COMAIL01.digitalglobe.com
Whole thread Raw
In response to create table as vs. create table like  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
List pgsql-general

Andreas K. wrote:
>
> In response to Ivan Sergio Borgonovo :
> > I just noticed something I found "unexpected".
> >
> > CREATE TABLE LIKE let you specify DEFAULT and Co.
> > CREATE TABLE AS doesn't.
> >
> > Is there a one step way to clone a table?
>
> with or without data?
>
> create table new_table (like old_table)
> create table new_table as select * from old_table

In addition:

CREATE TABLE new_table AS SELECT * FROM old_table LIMIT 0; -- also gets you a clone w/ no data

In 8.3 the (LIKE ...) construct allows for creation of indexes; in earlier versions I think they have to be done manually if they are desired. I think though that populating the table w/ indexes from a LIKE command would need an extra step to load data [which seems odd, seems it much faster usually to load data and then create indexes, etc.].

HTH,

Greg Williamson
Senior DBA
DigitalGlobe

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information and must be protected in accordance with those provisions. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

(My corporate masters made me say this.)


pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: create table as vs. create table like
Next
From: Ivan Sergio Borgonovo
Date:
Subject: Re: create table as vs. create table like