X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 6F4519FA2DB for ; Thu, 18 May 2006 11:06:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 65782-03 for ; Thu, 18 May 2006 11:06:36 -0300 (ADT) X-Greylist: delayed 00:24:29.807924 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 4CF959FA4EA for ; Thu, 18 May 2006 11:06:36 -0300 (ADT) Received: from ns1.officenet.no (ns1.officenet.no [193.212.174.3]) by svr4.postgresql.org (Postfix) with ESMTP id 77CDA5B5D40 for ; Thu, 18 May 2006 13:42:05 +0000 (GMT) Received: from [193.212.174.32] by ns1.officenet.no with esmtps (TLSv1:EXP1024-RC4-SHA:128) (Exim 4.60) (envelope-from ) id 1FgilI-0000Pq-SG for pgsql-sql@postgresql.org; Thu, 18 May 2006 15:42:00 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Constraint question Date: Thu, 18 May 2006 15:41:53 +0200 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200605181541.54299.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/142 X-Sequence-Number: 25173 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 o= nce=20 pr. businessfield_id pr. company so that only one businessfield can be=20 preferred for a company. Does anyone have an idea how to enforce this? =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager gpg public_key: http://dev.officenet.no/~andreak/public_key.asc =2D-----------------------+---------------------------------------------+ 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=F8yen | 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 | | =2D-----------------------+---------------------------------------------+