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

From: Mike Fowler <mike(at)mlfowler(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding a default value to a column after it exists
Date: 2011-04-13 16:25:05
Message-ID: 4DA5CE61.9000808@mlfowler.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Dave,

On 13/04/11 17:21, 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'".
>

Sure is something like that:

ALTER TABLE tablename ALTER COLUMN columnname SET DEFAULT expression;

For full documentation see:
http://www.postgresql.org/docs/9.0/static/sql-altertable.html

> Thanks for any help.
>

Regards,

--
Mike Fowler
Registered Linux user: 379787

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-04-13 16:29:27 Re: Adding a default value to a column after it exists
Previous Message Gauthier, Dave 2011-04-13 16:21:20 Adding a default value to a column after it exists