Constraint question

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: pgsql-sql(at)postgresql(dot)org
Subject: Constraint question
Date: 2006-05-18 13:41:53
Message-ID: 200605181541.54299.andreak@officenet.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have the following table:

create table onp_crm_businessfield_company(
businessfield_id integer not null references onp_crm_businessfield(id),
company_id integer not null references onp_crm_relation(id),
is_preferred boolean,
UNIQUE(businessfield_id, company_id)
);

I want a constraint on "is_preffered" so that it's only allowed to be set once
pr. businessfield_id pr. company so that only one businessfield can be
preferred for a company. Does anyone have an idea how to enforce this?

--
Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS | The most difficult thing in the world is to |
Hoffsveien 17 | know how to do a thing and to watch |
PO. Box 425 Skøyen | somebody else doing it wrong, without |
0213 Oslo | comment. |
NORWAY | |
Phone : +47 22 13 01 00 | |
Direct: +47 22 13 10 03 | |
Mobile: +47 909 56 963 | |
------------------------+---------------------------------------------+

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Alvaro Herrera 2006-05-18 14:00:14 Re: Add column and specify the column position in a table
Previous Message D'Arcy J.M. Cain 2006-05-18 13:41:41 Re: Encryption functions