foreign key with where clause

From: Mark Lybarger <mlybarger(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: foreign key with where clause
Date: 2016-08-18 17:10:16
Message-ID: CAKM-gm+-tykGb99J8fKrwv+ZeawmYxONPS+X9ULJ=ef-_3avhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 :).

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Branden Visser 2016-08-18 17:19:04 Re: foreign key with where clause
Previous Message Francisco Olarte 2016-08-18 16:41:21 Re: Sequential vs. random values - number of pages in B-tree