Re: create table as vs. create table like

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема Re: create table as vs. create table like
Дата
Msg-id 20081212140754.6aeaba0d@dawn.webthatworks.it
обсуждение исходный текст
Ответ на Re: create table as vs. create table like  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
On Fri, 12 Dec 2008 13:25:07 +0100
"A. Kretschmer" <andreas.kretschmer@schollglas.com> 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


В списке pgsql-general по дате отправления:

Предыдущее
От: "Gregory Williamson"
Дата:
Сообщение: Re: create table as vs. create table like
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Question with combining ANY with ilike