Re: Creating a column interger with default to not null

Поиск
Список
Период
Сортировка
От Thom Brown
Тема Re: Creating a column interger with default to not null
Дата
Msg-id AANLkTin00roUwq3PhFQq4wYp9VhxViWXG_ZNoMMf7ji1@mail.gmail.com
обсуждение исходный текст
Ответ на Creating a column interger with default to not null  (Chris Barnes <compuguruchrisbarnes@hotmail.com>)
Список 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 по дате отправления:

Предыдущее
От: "Wang, Mary Y"
Дата:
Сообщение: Trade Study on Oracle vs. PostgreSQL
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Creating a column interger with default to not null