pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Riya Verghese <riya.verghese@admissioncorp.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER records based on parameters in IN clause
Date: Mon, 27 Jun 2005 22:57:00 -0600
Message-ID: <20050628045700.GA18147@winnie.fuhr.org> (raw)
In-Reply-To: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>
References: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>

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/



view thread (16+ messages)  latest in thread

Message-ID: <20050628045700.GA18147@winnie.fuhr.org>
Permalink:  ../20050628045700.GA18147@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050628045700.GA18147@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, riya.verghese@admissioncorp.com
  Subject: Re: ORDER records based on parameters in IN clause
  In-Reply-To: <20050628045700.GA18147@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox