Re: help with pagila

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: help with pagila
Date: 2006-09-04 07:55:56
Message-ID: 44FBDC0C.5030902@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message M. Santosa 2006-09-05 07:22:29 pg_dump
Previous Message Aaron Bono 2006-09-03 23:17:46 Re: How to get the row that start a trigger