X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2C1353A5672 for ; Thu, 2 Dec 2004 02:46:18 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58658-04 for ; Thu, 2 Dec 2004 02:46:12 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id E669E3A5645 for ; Thu, 2 Dec 2004 02:46:14 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iB22jurI022693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Dec 2004 19:45:58 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iB22juKA040177; Wed, 1 Dec 2004 19:45:56 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iB22juWk040176; Wed, 1 Dec 2004 19:45:56 -0700 (MST) (envelope-from mfuhr) Date: Wed, 1 Dec 2004 19:45:56 -0700 From: Michael Fuhr To: Johan Henselmans Cc: pgsql-sql@postgresql.org Subject: Re: grouping a many to many relation set Message-ID: <20041202024556.GA40090@winnie.fuhr.org> References: <41AC3C7E.10201@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200412/18 X-Sequence-Number: 19638 On Wed, Dec 01, 2004 at 06:57:54AM +0100, Johan Henselmans wrote: > Richard Huxton wrote: > > > I think what's missing here is the explicit statement of which group > > these belong in. Without a value to sort/group by, there's nothing for > > your queries to "get a grip on". > > > > So - add a "group_id" column to the bank-book and receipt tables. Create > > a sequence to generate group id's on demand. > > Thanks for the reply. Adding a group_id column would defeat the whole > purpose of the relational model. I do not want to add a grouping > beforehand. How is an application going to know which records belong to which groups without a group ID? Or is a group ID acceptable as long as it's not part of the data, but rather generated by the query or function that does the grouping? > The grouping should take place according to certain criteria, in > this case: group all the records that have at least one of two > attributes in common. What about chains like this: bankbookdetid | receiptid ---------------+----------- 100 | 1 100 | 2 101 | 2 101 | 3 102 | 3 102 | 4 Should 1 be grouped with 2, 3, and 4 since 1 has an attribute in common with 2, 2 has an attribute in common with 3, and 3 has an attribute in common with 4? Or doesn't your model permit this situation? -- Michael Fuhr http://www.fuhr.org/~mfuhr/