Adding a default value to a column after it exists - Mailing list pgsql-general

From Gauthier, Dave
Subject Adding a default value to a column after it exists
Date
Msg-id 482E80323A35A54498B8B70FF2B87980048E2E6578@azsmsx504.amr.corp.intel.com
Whole thread Raw
Responses Re: Adding a default value to a column after it exists
Re: Adding a default value to a column after it exists
Re: Adding a default value to a column after it exists
List 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 by date:

Previous
From: "Andy Chambers"
Date:
Subject: Cursor metadata
Next
From: Mike Fowler
Date:
Subject: Re: Adding a default value to a column after it exists