Re: create table as vs. create table like

From: "Gregory Williamson" <Gregory(dot)Williamson(at)digitalglobe(dot)com>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: create table as vs. create table like
Date: 2008-12-12 12:46:35
Message-ID: 8B319E5A30FF4A48BE7EEAAF609DB233021F383D@COMAIL01.digitalglobe.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2008-12-12 13:07:54 Re: create table as vs. create table like
Previous Message A. Kretschmer 2008-12-12 12:25:07 Re: create table as vs. create table like