From: | Thom Brown <thom(at)linux(dot)com> |
---|---|
To: | Chris Barnes <compuguruchrisbarnes(at)hotmail(dot)com> |
Cc: | Postgres General Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Creating a column interger with default to not null |
Date: | 2010-09-24 15:10:28 |
Message-ID: | AANLkTin00roUwq3PhFQq4wYp9VhxViWXG_ZNoMMf7ji1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 24 September 2010 16:05, Chris Barnes
<compuguruchrisbarnes(at)hotmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2010-09-24 15:11:39 | Re: Restore/dump from "/usr/local/pgsql/data" directory |
Previous Message | Chris Barnes | 2010-09-24 15:05:43 | Creating a column interger with default to not null |