how to implement unusual constraint

From: danmcb <danielmcbrearty(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: how to implement unusual constraint
Date: 2007-06-24 09:54:57
Message-ID: 1182678897.876810.6330@n2g2000hse.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Say I have a table, say my_table, that is self-referencing. It looks
like this :

id integer pk,
orig_id integer references my_table(id),
.
.
.

Now this set of rows would be legal

id/orig_id
1 /1
2/1
3/1
4/4
5/4

but this not:

id/orig_id
1 /1
2/1
3/1
4/1
5/4

in other words: the row pointed to by orig_id cannot reference any row
other than itself.
How might I implement this as a constraint?
thanks,

Daniel

Responses

Browse pgsql-general by date

  From Date Subject
Next Message carter ck 2007-06-24 09:58:21 Re: Duplicate Key Violates Unique Contraint whenUpdating a table
Previous Message danmcb 2007-06-24 09:48:19 Re: finding items with 0 rels for a 0 to many relationship