From: | "Arguile" <arguile(at)lucentstudios(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Cc: | "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com> |
Subject: | Re: duplicating table |
Date: | 2002-01-10 17:06:07 |
Message-ID: | LLENKEMIODLDJNHBEFBOOEBJDPAA.arguile@lucentstudios.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Shaunn Johnson wrote
>
> Howdy:
> I know this will seem silly, but I'm trying to make a copy of a table
> with a few modifications.
[snip]
Both methods are possible, if you're created the table first then INSERT
INTO ... SELECT will work. Personally I don't often like using positional
inserts and that might be what's causing you to say "it doesn't work" (BTW
giving _why_ it doesn't work helps :). Try explicity stating what's going to
be inserted.
INSERT INTO new_table (field1, field2, field3, etc.)
SELECT field1, field2, field3, etc.
FROM original_table
;
Alternately you can create the table using the SELECT ... INTO (or the SQL92
way CREATE TABLE .. AS SELECT). Then add the other attributes after.
CREATE TABLE new_table AS SELECT * FROM original_table;
ALTER TABLE new_table ADD field datatype [options];
This won't get the attribute ordering you want though w/o having to muck
about w/ pg_attributes.attnum (something I wouldn't suggest).
From | Date | Subject | |
---|---|---|---|
Next Message | will trillich | 2002-01-10 17:22:55 | sequential invoice numbers? |
Previous Message | Peter Darley | 2002-01-10 16:55:50 | Re: Performance tips |