Thread: Create an empty copy of another table

Create an empty copy of another table

From
Thomas Weholt
Date:
Hi,

How do I create a new empty table that`s a copy of an allready existing one?
I need a way of putting the result of a select-statement into a temporary
table that`s an exact copy of the table it`s derived from and I`m not sure
how to do this. Obviously. I am just using one table to query at the time.

Thomas

Re: Create an empty copy of another table

From
Andrew McMillan
Date:
Thomas Weholt wrote:
>
> Hi,
>
> How do I create a new empty table that`s a copy of an allready existing one?
> I need a way of putting the result of a select-statement into a temporary
> table that`s an exact copy of the table it`s derived from and I`m not sure
> how to do this. Obviously. I am just using one table to query at the time.
>
> Thomas

    CREATE TABLE t2 AS SELECT * FROM t1;

There are other ways.  You mission is to learn those as well :-)

Cheers,
                    Andrew.

--
_____________________________________________________________________
            Andrew McMillan, e-mail: Andrew@cat-it.co.nz
Catalyst IT Ltd, PO Box 10-225, Level 22, 105 The Terrace, Wellington
Me: +64 (21) 635 694, Fax: +64 (4) 499 5596, Office: +64 (4) 499 2267

Re: Create an empty copy of another table

From
Andrew McMillan
Date:
Andrew McMillan wrote:
>
> Thomas Weholt wrote:
> >
> > Hi,
> >
> > How do I create a new empty table that`s a copy of an allready existing one?
> > I need a way of putting the result of a select-statement into a temporary
> > table that`s an exact copy of the table it`s derived from and I`m not sure
> > how to do this. Obviously. I am just using one table to query at the time.
> >
> > Thomas
>
>         CREATE TABLE t2 AS SELECT * FROM t1;

Woops!

    CREATE TABLE t2 AS SELECT * FROM t1 WHERE pkey != pkey;

:-)
                Andrew.

> --
> _____________________________________________________________________
>             Andrew McMillan, e-mail: Andrew@cat-it.co.nz
> Catalyst IT Ltd, PO Box 10-225, Level 22, 105 The Terrace, Wellington
> Me: +64 (21) 635 694, Fax: +64 (4) 499 5596, Office: +64 (4) 499 2267

--
_____________________________________________________________________
            Andrew McMillan, e-mail: Andrew@cat-it.co.nz
Catalyst IT Ltd, PO Box 10-225, Level 22, 105 The Terrace, Wellington
Me: +64 (21) 635 694, Fax: +64 (4) 499 5596, Office: +64 (4) 499 2267

Re: Create an empty copy of another table

From
Date:
I don't have time to test it out right now, but it
should be something like this:

SELECT * INTO tblTemp FROM tblExistingTable WHERE
nFieldOne = 5;

Look in the docs under SELECT INTO

David Boerwinkle
-----Original Message-----
From: Thomas Weholt <Thomas@cintra.no>
To: 'pgsql-novice@postgresql.org'
<pgsql-novice@postgresql.org>
Date: Wednesday, June 28, 2000 9:29 AM
Subject: [NOVICE] Create an empty copy of another
table


>Hi,
>
>How do I create a new empty table that`s a copy
of an allready existing one?
>I need a way of putting the result of a
select-statement into a temporary
>table that`s an exact copy of the table it`s
derived from and I`m not sure
>how to do this. Obviously. I am just using one
table to query at the time.
>
>Thomas