Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 977E679D55 for ; Thu, 12 Jul 2012 05:44:58 -0300 (ADT) Received: from mailout-de.gmx.net ([213.165.64.22]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SpF15-0001R8-Lh for pgsql-sql@postgresql.org; Thu, 12 Jul 2012 08:44:57 +0000 Received: (qmail invoked by alias); 12 Jul 2012 08:44:41 -0000 Received: from tmo-107-56.customers.d1-online.com (EHLO [2.169.164.220]) [80.187.107.56] by mail.gmx.net (mp037) with SMTP; 12 Jul 2012 10:44:41 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+0Lx4WbL+0N9YMKq6yTwuFfU5g6gU+YMpQvcBMFz RQBsKJNCDuDy0B Message-ID: <4FFE8E70.3060109@gmx.net> Date: Thu, 12 Jul 2012 10:44:32 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: Kretschmer Andreas , M.Mamin@intershop.de Subject: Re: Prevent double entries ... no simple unique index References: <4FFD3050.3010509@gmx.net> <20120711081607.GA17798@tux> <20120711082458.GA19013@tux> <20120712051445.GA5421@tux> In-Reply-To: <20120712051445.GA5421@tux> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/11 X-Sequence-Number: 36748 Am 12.07.2012 07:14, schrieb Andreas Kretschmer: > Marc Mamin wrote: > >> A partial index would do the same, but requires less space: >> >> create unique index on log(state) WHERE state IN (0,1); > OK, nice :) What if I have those states in a 3rd table? So I can see a state-history of when a state got set by whom. objects ( id serial PK, ... ) events ( id serial PK, object_id integer FK on objects.id, ... ) event_states ( id serial PK, event_id integer FK on events.id, state integer ) There still should only be one event per object that has state 0 or 1. Though here I don't have the object-id within the event_states-table. Is it still possible to have a unique index that needs to span over a join of events and event_states?