Re: foreign key with where clause

Поиск
Список
Период
Сортировка
От Branden Visser
Тема Re: foreign key with where clause
Дата
Msg-id CAOo4Obrt=ZnpoF41Kq8BueL+HtZ5oQGhhzApLP2oaTBmbNsa-g@mail.gmail.com
обсуждение исходный текст
Ответ на foreign key with where clause  (Mark Lybarger <mlybarger@gmail.com>)
Список pgsql-general
My first instinct would be to look into triggers. In addition to an FK
a(b_id) -> b(id), you could have an insert and update trigger on
a(b_id) and b(active) to ensure the additional constraints.

On Thu, Aug 18, 2016 at 1:10 PM, Mark Lybarger <mlybarger@gmail.com> wrote:
> I have two tables that i want to link with a FK where the child table record
> is "active".
>
> some googling shows that i could use a function and a check constraint on
> the function, but that only works for inserts, not updates on table b.
>
> create table a (int id, text name);
> create table b (int id, boolean active);
>
> alter table a add column b_id integer;
> -- how to do this?
> alter table a add foreign key (b_id) references b(id) where b.active == true
>
> help :).


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

Предыдущее
От: Mark Lybarger
Дата:
Сообщение: foreign key with where clause
Следующее
От: Manuel Gómez
Дата:
Сообщение: Re: foreign key with where clause