Re: Adding a New Column Specifically In a Table

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: Adding a New Column Specifically In a Table
Дата
Msg-id 4CB63071.3070601@iol.ie
обсуждение исходный текст
Ответ на Adding a New Column Specifically In a Table  (Carlos Mennens <carlos.mennens@gmail.com>)
Ответы Re: Adding a New Column Specifically In a Table  (Thom Brown <thom@linux.com>)
Список pgsql-general
On 13/10/2010 19:04, Carlos Mennens wrote:
> OK so I have read the docs and Google to try and find a way to add a
> new column to an existing table. My problem is I need this new column
> to be created 3rd  rather than just dumping this new column to the end
> of my table. I can't find anywhere how I can insert my new column as
> the 3rd table column rather than the last (seventh). Does anyone know
> how I can accomplish this or if it's even possible. Seems like a
> common task but I checked the documentation and may have missed it in
> my reading.
>

It isn't possible at the moment. This has come up a good bit in the
past, so you'll find debate in the archives...

One work-around is to add the column, and then do:

   create table new_table as
     select [columns in desired order] from old_table;

   drop table old_table;

   alter table new_table rename to old_table;

...remembering to deal with foreign key constraints as you go.

HTH

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

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

Предыдущее
От: Josh Kupershmidt
Дата:
Сообщение: Re: How to search ignoring spaces and minus signs
Следующее
От: ghatpande@vsnl.net
Дата:
Сообщение: Re: Adding a New Column Specifically In a Table