Re: Array values and foreign keys

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Pierre-Fr?d?ric Caillaud <lists(at)boutiquenumerique(dot)com>
Cc: Daniel Savard <dsavard(at)cids(dot)ca>, pgsql-general(at)postgresql(dot)org
Subject: Re: Array values and foreign keys
Date: 2004-10-27 18:01:46
Message-ID: 20041027180145.GA96686@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 27, 2004 at 05:59:46PM +0200, Pierre-Fr?d?ric Caillaud wrote:
>
> - add CHECK( test_array( yourcolumn )) in your table definition
> - create function test_array which takes an array and looks if all
> its elements are in your table T2, I do something like comparing the
> length of the array to SELECT count(1) FROM T2 WHERE key IN array

This provides only partial foreign key checking: depending on how
the application works, you might also need to ensure that updates
and deletes in T2 don't break the references in T1.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2004-10-27 18:08:39 Re: what could cause inserts getting queued up and db locking??
Previous Message Alvaro Herrera 2004-10-27 17:59:00 Re: page locking? too many btree indexes...