Re: duplicating table - Mailing list pgsql-general

From Campano, Troy
Subject Re: duplicating table
Date
Msg-id 9534B16F750ED2118CF90008C724C4460C2223EA@lmig-msg-20.lmig.com
Whole thread Raw
In response to duplicating table  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
Responses duplicating tables (accross databases)  (Jim Martinez <jjm@bigbigorg.org>)
List pgsql-general
In the first example you did, you need to specify column names:
 
 
 
insert into (col1, col2)
SELECT (col1, col2)
FROM table1
 
 
thanks!
 
 

 

-----Original Message-----
From: Johnson, Shaunn [mailto:SJohnson6@bcbsm.com]
Sent: Thursday, January 10, 2002 9:53 AM
To: pgsql-general@postgresql.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

pgsql-general by date:

Previous
From: Doug McNaught
Date:
Subject: Re: Performance tips
Next
From: Tina Messmann
Date:
Subject: index and seq scan