Re: how to implement a foreign key type constraint against a not unique column

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: how to implement a foreign key type constraint against a not unique column
Date: 2009-02-01 02:35:39
Message-ID: gm31pr$vkk$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2009-01-27, Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> wrote:
> On Jan 25, 2009, at 3:07 AM, Jasen Betts wrote:
>
>>> I want to use this column as a foreign key on a column in another
>>> table
>>> (column 2), but cannot without a full unique index.
>>
>> a full unique index is easy use an expression that's null for -1.
>>
>> create unique index foobar on foo( ( case fee when -1 then null else
>> fee end ) );
>
>
> anything wrong with create unique index foobar on foo where fee <> -1 ?

neither way works for a foreign key.

easiest solution seems to be to insert a record matching -1 in the
other table (with all other fields null)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2009-02-01 02:38:18 Re: Rollback of Query Cancellation
Previous Message Scott Marlowe 2009-02-01 01:11:58 Re: Indices types, what to use. Btree, Hash, Gin or Gist