Received: from acheron.rime.com.au (root@albatr.lnk.telstra.net [139.130.54.222]) by hub.org (8.9.3/8.9.3) with ESMTP id CAA61254 for ; Tue, 25 Jan 2000 02:54:58 -0500 (EST) (envelope-from pjw@rhyme.com.au) Received: from oberon (Oberon.rime.com.au [203.8.195.100]) by acheron.rime.com.au (8.9.3/8.9.3) with SMTP id SAA08550; Tue, 25 Jan 2000 18:53:34 +1100 Message-Id: <3.0.5.32.20000125185459.00cf7450@mail.rhyme.com.au> X-Sender: pjw@mail.rhyme.com.au X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Tue, 25 Jan 2000 18:54:59 +1100 To: Tom Lane From: Philip Warner Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace Cc: Don Baccus , Chris Bitmead , pgsql-hackers@postgreSQL.org In-Reply-To: <12269.948780766@sss.pgh.pa.us> References: <3.0.5.32.20000125170026.0357d8f0@mail.rhyme.com.au> <11879.948776470@sss.pgh.pa.us> <3.0.5.32.20000125150557.036121c0@mail.rhyme.com.au> <2295.948765015@sss.pgh.pa.us> <3.0.5.32.20000125140349.035768d0@mail.rhyme.com.au> <3.0.5.32.20000125150557.036121c0@mail.rhyme.com.au> <3.0.5.32.20000125170026.0357d8f0@mail.rhyme.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" At 01:12 25/01/00 -0500, Tom Lane wrote: >Philip Warner writes: >>>> SQL in general doesn't believe that tuple ordering has any semantic >>>> significance --- you can ask for ORDER BY, but that's only honored >>>> at the end stage of SELECT result delivery, not necessarily anywhere >>>> in the bowels of a query. > >> Out of curiosity, does the SQL spec give any rules or guidelines about when >> aggregates should be applied to resultant rows? Or is it one of the >> implementation-dependant things? > >Well, SQL's conceptual model is perfectly clear about the processing >work flow of a SELECT: after you've constructed the tuple set (which >might involve joining multiple relations), you apply the WHERE condition >to filter out uninteresting tuples. Then you apply GROUP BY (if given) >to divvy the tuples into groups. Then you apply HAVING to eliminate >uninteresting groups. Then you apply aggregate functions (if any) to >individual groups, or to the whole filtered result set if no groups. >Finally you apply ORDER BY to whatever's left. Thanks, but now I'm confused. I would have thought that aggregates went *before* the having clause, since at least one DB I know allows: select job_type,avg(age) from where group by job_type having avg(age) > 70; ie. the use of aggregate results in the 'having' clause. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: +61-03-5367 7422 | _________ \ Fax: +61-03-5367 7430 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/