Re: Creating a column interger with default to not null - Mailing list pgsql-general

From Thom Brown
Subject Re: Creating a column interger with default to not null
Date
Msg-id AANLkTin00roUwq3PhFQq4wYp9VhxViWXG_ZNoMMf7ji1@mail.gmail.com
Whole thread Raw
In response to Creating a column interger with default to not null  (Chris Barnes <compuguruchrisbarnes@hotmail.com>)
List pgsql-general
On 24 September 2010 16:05, Chris Barnes
<compuguruchrisbarnes@hotmail.com> wrote:
>
> I am confused with what this is telling me.
> I have a table and I am trying to add a new column with constraint not null.
>
>
> What am I missing?
> Chris
>
>
> pgdb001=> alter table schema.table add COLUMN column_name integer not null;
> ERROR:  column "column_name" contains null values

What it's telling you is that the column can't contain null values,
but you're adding a new column with no default, so it will naturally
use null.

Try adding a default like:

ALTER TABLE schema.table ADD COLUMN column_name integer NOT NULL DEFAULT 0;

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

pgsql-general by date:

Previous
From: "Wang, Mary Y"
Date:
Subject: Trade Study on Oracle vs. PostgreSQL
Next
From: Adrian Klaver
Date:
Subject: Re: Creating a column interger with default to not null