X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 17D40D1B8E0; Fri, 29 Aug 2003 08:53:09 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 04455-04; Fri, 29 Aug 2003 05:52:40 -0300 (ADT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 26C8CD1B8BB; Fri, 29 Aug 2003 05:52:38 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 19sezk-0002Mw-0Z; Fri, 29 Aug 2003 09:52:36 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 8643416363; Fri, 29 Aug 2003 09:52:34 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id CDD9C1635D; Fri, 29 Aug 2003 09:52:33 +0100 (BST) From: Richard Huxton To: Anuradha Ratnaweera , pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: Re: [SQL] Unique constraints for a list Date: Fri, 29 Aug 2003 09:52:33 +0100 User-Agent: KMail/1.5 References: <20030829055056.GA13802@aratnaweera.virtusa.com> In-Reply-To: <20030829055056.GA13802@aratnaweera.virtusa.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308290952.33833.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/1697 X-Sequence-Number: 48112 On Friday 29 August 2003 06:50, Anuradha Ratnaweera wrote: [snipped description of groups consisting of unique lists of members, i.e. group A contains (1,2,3) so B can't contain the same] I was looking at something almost identical a few days ago. > Then we added a unique string field to t3 which is a comma seperated and > sorted list of group members. But when this is done, the DB is no > longer normalized. I looked at this, but I was planning to use this "member_key" as an addition to the two tables and just keep it up to date with triggers. In your case add the comma-separated-list to t1 but keep t2. This seemed to work OK speed-wise and was no less normalised than having a "group_size" field in t1 that triggers kept up to date. > Are there any other approaches we can take? Or are we missing something > obvious here? The other approach I looked at was to build a new group in a test table, join its members to the real table and compare the number of matches to the size of both groups (for this a pre-calculated size came in useful). If the number of matches equalled the size of both our new list and an existing list then they were duplicates. The query wasn't as bad as I first feared, but it definitely helped to build it up one step at a time. Testing showed that the second method was too slow for my particular need (bursty updates) but it might work for you. -- Richard Huxton Archonet Ltd