Re: trigger to enforce FK with nulls? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: trigger to enforce FK with nulls?
Date
Msg-id 20060412182501.X57788@megazone.bigpanda.com
Whole thread Raw
In response to trigger to enforce FK with nulls?  (George Young <gry@ll.mit.edu>)
List pgsql-sql
On Wed, 12 Apr 2006, George Young wrote:

> [PostgreSQL 8.1.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1]
>
> I'm starting to use lots of foreign key constraints to keep my
> data clean.  In one case, however, I need to allow null values
> for the key.  E.g.:
>
> create table opset_steps(opset text, step text, step_num int);
> create table steps(run text, step text, opset text, user text, step_num int);
>
> The constraint on steps should be:
>    steps.(opset,step) must be found in opset_steps.(opset,step) UNLESS steps.opset is null.

The default foreign key case should not error if either steps.opset or
steps.step is null.  If you're seeing something else, can you give a
complete test case?


pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: trigger to enforce FK with nulls?
Next
From: ivan marchesini
Date:
Subject: how to solve this problem