Re: Constraint question - Mailing list pgsql-sql

From Markus Schaber
Subject Re: Constraint question
Date
Msg-id 446CA301.20305@logix-tt.com
Whole thread Raw
In response to Constraint question  (Andreas Joseph Krogh <andreak@officenet.no>)
Responses Re: Constraint question
List pgsql-sql
Hi, Andreas,

Andreas Joseph Krogh wrote:

> 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?

CREATE UNIQUE INDEX foo ON onp_crm_businessfield_company(company_id)
WHERE is_prefferred;

HTH,
Markus

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org


pgsql-sql by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Add column and specify the column position in a table
Next
From: "Guillaume Lelarge"
Date:
Subject: Re: Add column and specify the column position in a table