| От | Harald Fuchs |
|---|---|
| Тема | Re: Adding a default value to a column after it exists |
| Дата | |
| Msg-id | 86d3ko6fz9.fsf@mgm.protecting.net обсуждение исходный текст |
| Ответ на | Adding a default value to a column after it exists ("Gauthier, Dave" <dave.gauthier@intel.com>) |
| Список | pgsql-general |
In article <20110413163120.GU24471@shinkuro.com>, Andrew Sullivan <ajs@crankycanuck.ca> writes: > On Wed, Apr 13, 2011 at 09:21:20AM -0700, Gauthier, Dave wrote: >> Is there a way to add a default value definition to an existing column? Something like an "alter table... alter column...default 'foo'". > ALTER TABLE table ALTER [ COLUMN ] column SET DEFAULT expression > (see http://www.postgresql.org/docs/9.0/interactive/sql-altertable.html) > Note that this doesn't actually update the fields that are NULL in the > column already. For that, once you had the default in place, you > could do > UPDATE table SET column = DEFAULT WHERE column IS NULL And you probably want to do ALTER TABLE table ALTER [ COLUMN ] column SET NOT NULL after that.
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера