foreign key with where clause - Mailing list pgsql-general

From Mark Lybarger
Subject foreign key with where clause
Date
Msg-id CAKM-gm+-tykGb99J8fKrwv+ZeawmYxONPS+X9ULJ=ef-_3avhA@mail.gmail.com
Whole thread Raw
Responses Re: foreign key with where clause  (Branden Visser <mrvisser@gmail.com>)
Re: foreign key with where clause  (Manuel Gómez <targen@gmail.com>)
List pgsql-general
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 by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: Sequential vs. random values - number of pages in B-tree
Next
From: Branden Visser
Date:
Subject: Re: foreign key with where clause