Re: Adding a New Column Specifically In a Table

Поиск
Список
Период
Сортировка
От Darren Duncan
Тема Re: Adding a New Column Specifically In a Table
Дата
Msg-id 4CB632D8.7000304@darrenduncan.net
обсуждение исходный текст
Ответ на Adding a New Column Specifically In a Table  (Carlos Mennens <carlos.mennens@gmail.com>)
Ответы Re: Adding a New Column Specifically In a Table  (Rajesh Kumar Mallah <mallah.rajesh@gmail.com>)
Список pgsql-general
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.
>
> ALTER TABLE users ADD COLUMN employer VARCHAR(50) NOT NULL;
>
> The above command dumps the 'employer' column at the very end of my
> table which is not what I want.
>
> Thanks for any assistance...

Why do you want to do this?

Columns should only be referenced by their names and not by any kind of ordinal
position.  You should treat the list of columns as being an unordered set, and
so your new column isn't actually in 7th place, and you can display your columns
in any order you want.  Relying on any intrinsic ordinal position of columns is
just going to get you into trouble.

I also didn't see from
http://www.postgresql.org/docs/9.0/interactive/sql-altertable.html how you would
do what you asked.

The page http://wiki.postgresql.org/wiki/Alter_column_position also shows some
contrivances you could go through to get what you want, but it is better to just
not care about order in the first place.

-- Darren Duncan

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

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: Adding a New Column Specifically In a Table
Следующее
От: Bruno Baguette
Дата:
Сообщение: How to iterate fields into a NEW.* RECORD in a TRIGGER procedure ?