Received: from acheron.rime.com.au (root@albatr.lnk.telstra.net [139.130.54.222]) by hub.org (8.10.1/8.10.1) with ESMTP id e7849bG93249 for ; Tue, 8 Aug 2000 00:09:37 -0400 (EDT) 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 OAA05426; Tue, 8 Aug 2000 14:10:00 +1000 Message-Id: <3.0.5.32.20000808141008.024123f0@mail.rhyme.com.au> X-Sender: pjw@mail.rhyme.com.au X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Tue, 08 Aug 2000 14:10:08 +1000 To: Tom Lane From: Philip Warner Subject: Re: Subselect and limit/order? Cc: pgsql-sql@hub.org In-Reply-To: <6255.965663205@sss.pgh.pa.us> References: <3.0.5.32.20000808004355.02772100@mail.rhyme.com.au> <3.0.5.32.20000808004355.02772100@mail.rhyme.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200008/60 At 11:46 7/08/00 -0400, Tom Lane wrote: >Philip Warner writes: >> Just wondering why subselect expressions can not have a limit/order clause, > >We could ignore the spec and implement this as an extension, but I'd >want to see some fairly compelling arguments why it's a good idea. >(In other words, why do you know better than the designers of SQL?) Well, it's not *just* me. Both Dec/RDB and SQL/Server implement ORDER BY in subqueries. SQL/Server insists on a limit statement in this case, whereas Dec/Rdb just dies if more than one row is returned. It is a very useful thing when you are scanning though sequential records that are time based, or have ID's that have 'holes' in the sequence. eg. in the case of time-based data, you can derive durations. But it can be done by writing a plpgsql function, so it's not a big issue. >> It can obviously be done in two select statements, but I was just wondering >> if it's an oversight or a planner problem? > >I'd say mostly an executor problem, actually. Nobody's figured out >where the executor would need to be hacked to support tuple-limits >applied elsewhere than the top level of a select. Wouldn't is also have a fair impact on the planner? Or does it always assume that subselects only return one row? ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/