Re: duplicating table

From: "Nick Fankhauser" <nickf(at)ontko(dot)com>
To: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: duplicating table
Date: 2002-01-10 16:07:27
Message-ID: NEBBLAAHGLEEPCGOBHDGCEMKECAA.nickf@ontko.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Shaunn-

Here's a simplified version using your tables (you'll need to add all of the
rows you care about:

insert into table_two (name, riskgrp) values (select name,riskgrp from
table_one);

-Nick

--------------------------------------------------------------------------
Nick Fankhauser nickf(at)ontko(dot)com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Johnson, Shaunn
Sent: Thursday, January 10, 2002 9:53 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] duplicating table

Howdy:
I know this will seem silly, but I'm trying to
make a copy of a table with a few modifications.
I have a table like so:
[snip]
Attribute | Type | Modifier
-----------+-------------------+----------
name | character varying |
riskgrp | character(12) |
address | character varying |
city | character varying |
state | character varying |
zip | character varying |
pcgname | character varying |
[/snip]
and i want to create a new table like so:
[snip]
Attribute | Type | Modifier
-----------+-------------------+----------
name | character varying |
riskgrp | character(12) |
address | character varying |
address2 | character varying |
city | character varying |
state | character varying |
zip | character varying |
pcgname | character varying |
mailcode | character(5) |
[/snip]
I can alter the table to add the two
new columns, but I wanted to know if
I can copy the data from the old table
into the new table and put the column
data in the appropriate places
(leaving column: address2 and mailcode empty)?
I have been trying something like:
[example]
insert into t2_ref_pcg_address
select name,riskgrp,address,,city,state,zi p,pcgname from t_ref_pcg_address;
[/example]
And
[example]
select
name,riskgrp,address,,city,state,zip,pcgname from t_ref_pcg_address into
t2_ref_pcg_address;
[/example]
Neither works.
Any suggestions?
Thanks!

-X

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-01-10 16:08:44 Re: Query planner isn't using my indices
Previous Message Stephan Szabo 2002-01-10 16:07:25 Re: duplicating table