Adding a default value to a column after it exists

Поиск
Список
Период
Сортировка
От Gauthier, Dave
Тема Adding a default value to a column after it exists
Дата
Msg-id 482E80323A35A54498B8B70FF2B87980048E2E6578@azsmsx504.amr.corp.intel.com
обсуждение исходный текст
Ответы Re: Adding a default value to a column after it exists  (Mike Fowler <mike@mlfowler.com>)
Re: Adding a default value to a column after it exists  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Adding a default value to a column after it exists  (Andrew Sullivan <ajs@crankycanuck.ca>)
Список pgsql-general

Is there a way to add a default value definition to an existing column?  Something like an "alter table... alter column... default 'foo'".

 

I thought of a clumsy way to do this... create a temp column, set it's value to that of the column to be altered, drop the column to be altered, redefine it with the default, shunt all the values in the temp column over to the new column and then drop the temp column.  But I have before and after triggers on the table that react to changes in this column (not to mention the need for it's existence). 

 

I could add something to the before trigger to do this too. But it would be cleaner to do this as a column property.

 

Thanks for any help.

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

Предыдущее
От: "Andy Chambers"
Дата:
Сообщение: Cursor metadata
Следующее
От: Mike Fowler
Дата:
Сообщение: Re: Adding a default value to a column after it exists