create table like syntax

Lists: pgsql-admin
From: David Durham <ddurham(at)vailsys(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: create table like syntax
Date: 2005-10-06 03:04:10
Message-ID: 4344942A.3040506@vailsys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

is there a syntax that would look something like:

create table newTable like oldTable without indexes || records ||
constraints with indexes || records || constraints

built into postgres?


From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: David Durham <ddurham(at)vailsys(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: create table like syntax
Date: 2005-10-06 03:36:36
Message-ID: 20051006033636.GA12593@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Wed, Oct 05, 2005 at 10:04:10PM -0500, David Durham wrote:
> is there a syntax that would look something like:
>
> create table newTable like oldTable without indexes || records ||
> constraints with indexes || records || constraints
>
> built into postgres?

What do you want to do with it? If I understand what you want to do, it
is supported as long as you use ; in place of your ||.

--
Alvaro Herrera Architect, http://www.EnterpriseDB.com
"La fuerza no está en los medios físicos
sino que reside en una voluntad indomable" (Gandhi)


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: David Durham <ddurham(at)vailsys(dot)com>
Subject: Re: create table like syntax
Date: 2005-10-07 12:36:51
Message-ID: 43466BE3.40200@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

David Durham wrote:
> is there a syntax that would look something like:
>
> create table newTable like oldTable without indexes || records ||
> constraints with indexes || records || constraints
>
> built into postgres?
>

Try this:

create table newTable as
select * from oldTable limit 0;

Regards
Gaetano Mendola


From: David Durham <ddurham(at)vailsys(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: create table like syntax
Date: 2005-10-07 14:48:12
Message-ID: 43468AAC.5010509@vailsys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Alvaro Herrera wrote:
> On Wed, Oct 05, 2005 at 10:04:10PM -0500, David Durham wrote:
>
>>is there a syntax that would look something like:
>>
>> create table newTable like oldTable without indexes || records ||
>>constraints with indexes || records || constraints
>>
>>built into postgres?
>
>
> What do you want to do with it? If I understand what you want to do, it
> is supported as long as you use ; in place of your ||.

Well, I should say that the with and without should probably be mutually
exclusive. I don't know, haven't thought about it that much, but I find
myself creating a lot of the same table over and over from time to time
as I try to analyze some data. Would be nice to say, hey, create a copy
of this table with indexes and possibly records and constraints. Or
just a bare copy or something like that, but have a lot of different
options for this kind of thing.

- Dave