Re: DEFERRABLE NOT NULL constraint

Поиск
Список
Период
Сортировка
От Виктор Егоров
Тема Re: DEFERRABLE NOT NULL constraint
Дата
Msg-id CAGnEbog40at+XCnqYrJhph8rqncRiuJ88=e0TJ6LztTGycEkJA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: DEFERRABLE NOT NULL constraint  (Darren Duncan <darren@darrenduncan.net>)
Список pgsql-general
2013/2/5 Darren Duncan <darren@darrenduncan.net>:
> I'd like to know what value there is in making NOT NULL and CHECK
> deferrable.

Consider such schema sample:
- you have tables “groups” and “group_items”
- each group must have at least one item
- each group must have a “master” item, that is denoted in
groups.master_item_id column
- groups.group_id, groups.master_item_id, group_items.item_id and
group_items.group_id should be NOT NULL
- you use “serial” type for the KEY columns

Now, when you're creating a new group:
- you cannot insert a row into the groups, as master_item_id is not
yet known and NULL is not allowed;
- you cannot insert a row into the group_items, as you need to know
group_id, FK can be deferred, but NULL is not allowed.


All this works pretty good if one don't use “serial” type for the keys and
explicitly calls nextval() on the corresponding sequences first.


--
Victor Y. Yegorov



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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: DEFERRABLE NOT NULL constraint
Следующее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: DEFERRABLE NOT NULL constraint