[GENERAL] Best way to allow column to initially be null?

Поиск
Список
Период
Сортировка
От Glen Huang
Тема [GENERAL] Best way to allow column to initially be null?
Дата
Msg-id 0780AF5A-AE89-4255-9857-EC3EF91570A3@gmail.com
обсуждение исходный текст
Ответы Re: [GENERAL] Best way to allow column to initially be null?  (Berend Tober <btober@computer.org>)
Список pgsql-general
Hi,

I’m trying to make a column have these properties:

1. When a row is inserted, this column is allowed to be null.
2. When the row is updated, no null can be assigned to it this column.

I initially thought I can drop the not null constraint before insertion and turn it back on after that, but after
readingthe doc it seems turning on not null constraint requires not columns contain null value, so looks like it won’t
work.

My current approach is to not set the not null constraint in the table and use a before update trigger to manually
raiseexception when the column is null. But it doesn’t seem as elegant. 

Is there a better way?

Regards,
Glen

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

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

Предыдущее
От: Andy Colson
Дата:
Сообщение: Re: [GENERAL] PG 10 and perl
Следующее
От: Berend Tober
Дата:
Сообщение: Re: [GENERAL] Best way to allow column to initially be null?