Constraint that compares and limits field values

From: MargaretGillon(at)chromalloy(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Constraint that compares and limits field values
Date: 2006-01-24 17:52:25
Message-ID: OF37DD51B2.024C7F1A-ON88257100.0060BCB2-88257100.00618341@CHROMALLOY.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table that I am using to hold keys for M:M relationships. I
have six fields that can hold the keys and I do this because I validate
the key with a foreign key constraint. Fields evevid1, evevid2 hold keys
from the event table, evreid1, evreid2 hold keys from the resource table,
etc. The 0 works with the FK constraints because in each table being
referenced I have a record with id = 0 that is empty. Each row should
only have two foreign key values and the other key field values are 0.

How do I put a constraint on the Insert / Update to make sure that only
two fields out of the six have a value > 0 in them.

I want to make sure that one of these three fields has a value > 0 and the
other two are 0.
evevid1 int4
evenid1 int4
evreid1 int4

Same here. I want to make sure that one of these three fields has a value
> 0 and the other two are 0.
evevid2 int4
evenid2 int4
evreid2 int4

Please reply to me as well as the list because I get the digest version
and it might take a while to get the reply there.

Thank you,
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
*** ***
Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297

This e-mail message and any attachment(s) are for the sole use of the
intended recipient(s) and may contain proprietary and/or confidential
information which may be privileged or otherwise protected from
disclosure. Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient(s), please contact the
sender by reply email and destroy the original message and any copies of
the message as well as any attachment(s) to the original message.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Hallgren 2006-01-24 18:45:00 Re: user defined function
Previous Message Brian A. Seklecki 2006-01-24 17:29:02 Re: Backup and Restore mechanism in Postgres