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 036E49F9C18 for ; Thu, 18 May 2006 13:38:23 -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 35597-10 for ; Thu, 18 May 2006 13:38:13 -0300 (ADT) X-Greylist: delayed 06:57:23.745243 by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id EEBE09F9316 for ; Thu, 18 May 2006 13:38:12 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (T96b4.t.pppool.de [89.55.150.180]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 1E7AE65800; Thu, 18 May 2006 18:39:27 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 320C2185BB4EF; Thu, 18 May 2006 18:38:25 +0200 (CEST) Message-ID: <446CA301.20305@logix-tt.com> Date: Thu, 18 May 2006 18:38:25 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andreas Joseph Krogh Cc: pgsql-sql@postgresql.org Subject: Re: Constraint question References: <200605181541.54299.andreak@officenet.no> In-Reply-To: <200605181541.54299.andreak@officenet.no> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/146 X-Sequence-Number: 25177 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