X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7EBC79FB505 for ; Mon, 4 Sep 2006 05:10:16 -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 50052-02-6 for ; Mon, 4 Sep 2006 05:10:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 7C9F19FA5EA for ; Mon, 4 Sep 2006 04:55:59 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (80-219-241-140.dclient.hispeed.ch [80.219.241.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id CDCD8656BE for ; Mon, 4 Sep 2006 09:58:09 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id B84EB18151EBC for ; Mon, 4 Sep 2006 09:55:56 +0200 (CEST) Message-ID: <44FBDC0C.5030902@logix-tt.com> Date: Mon, 04 Sep 2006 09:55:56 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.5 (X11/20060812) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: help with pagila References: <32cabba0609010631t233d13f9o38edba0483a2446c@mail.gmail.com> <20060901152116.GE17178@phlogiston.dyndns.org> <32cabba0609011026r6616a73bhe80b336f18aa84ac@mail.gmail.com> <20060901174040.GF17178@phlogiston.dyndns.org> <20520.1157142108@sss.pgh.pa.us> In-Reply-To: <20520.1157142108@sss.pgh.pa.us> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.155 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/16 X-Sequence-Number: 26227 Hi, Tom, Tom Lane wrote: > If film_id is a primary key for film, then it's actually legal per SQL99 > (though not in earlier SQL specs) to just GROUP BY film_id and then > reference the other columns of film without explicit grouping, because > clearly there can be only one value of them per film_id value. However > the quoted query includes ungrouped references to other tables as well, > and it's not immediately obvious that those references must have unique > values for any one value of film_id. In situations like this, I often missed (and sometimes implemented) a simple "first()" aggregate to put around those other columns. Some of those cases could be fixed by creative use of "DISTINCT ON", but sometimes lead to suboptimal query plans (due to the useless sorting). 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