Re: duplicating table

Поиск
Список
Период
Сортировка
От Arguile
Тема Re: duplicating table
Дата
Msg-id LLENKEMIODLDJNHBEFBOOEBJDPAA.arguile@lucentstudios.com
обсуждение исходный текст
Ответ на duplicating table  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
Список 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).



В списке pgsql-general по дате отправления:

Предыдущее
От: "Peter Darley"
Дата:
Сообщение: Re: Performance tips
Следующее
От: Doug McNaught
Дата:
Сообщение: Re: Performance tips