Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 324DF9FB552 for ; Sat, 17 Feb 2007 12:31:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 46782-06 for ; Sat, 17 Feb 2007 12:31:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 311F69FB539 for ; Sat, 17 Feb 2007 12:31:36 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l1HGVY7b019516; Sat, 17 Feb 2007 11:31:34 -0500 (EST) To: "Rajesh Kumar Mallah" cc: pgsql-sql@postgresql.org Subject: Re: ordering of selected rows from an ordered subselect In-reply-to: References: Comments: In-reply-to "Rajesh Kumar Mallah" message dated "Sat, 17 Feb 2007 15:02:06 +0530" Date: Sat, 17 Feb 2007 11:31:34 -0500 Message-ID: <19515.1171729894@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.069 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200702/184 X-Sequence-Number: 27518 "Rajesh Kumar Mallah" writes: > select id , name , expensive_func(name) from > ( select id , name from tab order by c1 desc limit 15) as foo ; > is it guaranteed that the final result is order by c1 ? The sub-select's output will be emitted in the specified order. What happens after that depends on the outer query, but if you don't have any joining or grouping then it's a reasonably safe bet that the final output will be in the same order. regards, tom lane