Search Postgresql Archives

Re: Adding a default value to a column after it exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

IIRC.

A

-- 
Andrew Sullivan
ajs@xxxxxxxxxxxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux