Search Postgresql Archives

Re: create table as vs. create table like

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 12 Dec 2008 13:25:07 +0100
"A. Kretschmer" <andreas.kretschmer@xxxxxxxxxxxxxx> 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

They achieve partially what I'm looking for. Not that I really need
to save 100 bytes but as said it looked "unexpected" since most of
what's needed is almost there but is split across the 2 commands in
a "strange way".

create table like clones the "structure" including indexes, default
and constraint but not the content.

create table as clones the schema and the content but not the
indexes, default and constraints.

create table newtable (like oldtable including defaults, constraints,
indexes); -- I should test the syntax for multiple "including"

insert into newtable select * from oldtable;

Is the best thing that come close to cloning a table. On the top of
my head CHECKS will still miss.

Without cloning indexes, defaults, constraints create table as does
look really redundant (select into newtable) and create table like is
"almost there".

Gregory's remark about index creation is interesting... but well it
just would depend on the implementation.

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux