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 BAA25996 for ; Tue, 25 Jan 2000 01:00:32 -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 QAA07476; Tue, 25 Jan 2000 16:59:02 +1100 Message-Id: <3.0.5.32.20000125170026.0357d8f0@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 17:00:26 +1100 To: Don Baccus , Tom Lane From: Philip Warner Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace Cc: Chris Bitmead , pgsql-hackers@postgreSQL.org In-Reply-To: <3.0.1.32.20000124212022.00f70720@mail.pacifier.com> References: <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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" At 21:20 24/01/00 -0800, Don Baccus wrote: >At 12:01 AM 1/25/00 -0500, Tom Lane wrote: >>Philip Warner writes: >>> Just a thought, but would I be right in saying that this could be easily >>> done with the addition of a new aggregate function 'FIRST', which simply >>> returns the first value sent to it? Since the aggregates operate a row at >>> a time, you are guaranteed a consistent set of values, I think. >> >>No, because the system doesn't guarantee to deliver tuples to the >>aggregate in any particular order. > >In fact, this is a KEY notion behind RDBMS systems...queries return an >unordered set, pure and simple, unless you supply an "order" clause >(though "group by" appears to be implemented by ordering in various >RDBMS systems, that's an efficiency hack not a given AFAIK). That's why there was an 'order by' in the query (there should have also been a 'group by', to make it valid SQL). I had (naievely) assumed that the aggregates would be passed the rows in sorted order. >>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. > >Yep... > 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? ---------------------------------------------------------------- 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 |/