Re: Constraint question

Поиск
Список
Период
Сортировка
От Markus Schaber
Тема Re: Constraint question
Дата
Msg-id 446CA301.20305@logix-tt.com
обсуждение исходный текст
Ответ на Constraint question  (Andreas Joseph Krogh <andreak@officenet.no>)
Ответы Re: Constraint question  (Andreas Joseph Krogh <andreak@officenet.no>)
Список 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 по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: Add column and specify the column position in a table
Следующее
От: "Guillaume Lelarge"
Дата:
Сообщение: Re: Add column and specify the column position in a table