X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5DB20528C1 for ; Tue, 28 Jun 2005 01:57:16 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13235-09 for ; Tue, 28 Jun 2005 04:57:07 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 337D852835 for ; Tue, 28 Jun 2005 01:57:06 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j5S4v1FN084619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Jun 2005 22:57:03 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j5S4v1lY018194; Mon, 27 Jun 2005 22:57:01 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j5S4v1tZ018193; Mon, 27 Jun 2005 22:57:01 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 27 Jun 2005 22:57:00 -0600 From: Michael Fuhr To: Riya Verghese Cc: pgsql-sql@postgresql.org Subject: Re: ORDER records based on parameters in IN clause Message-ID: <20050628045700.GA18147@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/331 X-Sequence-Number: 21932 On Mon, Jun 27, 2005 at 09:15:15AM -0700, Riya Verghese wrote: > > I have a stmt where the outer-query is limited by the results of the > inner query. I would like the outer query to return records in the same > order as the values provided in the IN clause (returned form the inner > query). If you want a particular order then use ORDER BY. The SQL standard says that without an ORDER BY clause, row order is implementation- dependent; the PostgreSQL documentation also says the same thing: http://www.postgresql.org/docs/8.0/static/queries-order.html "If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen." -- Michael Fuhr http://www.fuhr.org/~mfuhr/