Question about NOT NULL and default values.

Поиск
Список
Период
Сортировка
От Tim Uckun
Тема Question about NOT NULL and default values.
Дата
Msg-id 855e4dcf0810162009k7dd76436jfa7cd87fe107b053@mail.gmail.com
обсуждение исходный текст
Ответы Re: Question about NOT NULL and default values.  (Chris <dmagick@gmail.com>)
Re: Question about NOT NULL and default values.  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Re: Question about NOT NULL and default values.  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Re: Question about NOT NULL and default values.  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-general
Hey all.

I am using postgres 8.3 with a rails application. I have a column
defined like this.

ALTER TABLE provisions ADD COLUMN provider_id integer;
ALTER TABLE provisions ALTER COLUMN provider_id SET STORAGE PLAIN;
ALTER TABLE provisions ALTER COLUMN provider_id SET NOT NULL;
ALTER TABLE provisions ALTER COLUMN provider_id SET DEFAULT 0;

In rails if I don't specify the provider_id the ORM passes a NULL in
the SQL to insert or update and the query blows up.

In order to get around that problem and removed the NOT NULL
constraint but postgres just puts the NULL value in the column instead
of the default value.

Is there a way to change this behavior so that an attempt to set the
column to NULL will result in the default value being put in the
field?

Thanks.

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Drop database / database in use question
Следующее
От: Chris
Дата:
Сообщение: Re: Question about NOT NULL and default values.