Re: ORDER records based on parameters in IN clause

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Riya Verghese <riya(dot)verghese(at)admissioncorp(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER records based on parameters in IN clause
Date: 2005-06-28 04:57:00
Message-ID: 20050628045700.GA18147@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kenneth Gonsalves 2005-06-28 06:41:29 Re: ENUM like data type
Previous Message Michael Fuhr 2005-06-27 20:35:12 Re: pg_attribute.attlen -1 for varchar e pbchar fields