Re: Is it possible to make the order of output the same as the order of input parameters?

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is it possible to make the order of output the same as the order of input parameters?
Date: 2010-06-02 14:55:41
Message-ID: 20100602145541.GS20550@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 02, 2010 at 04:47:01PM +0200, A. Kretschmer wrote:
> In response to Sam Mason :
> > SELECT c.*
> > FROM customer c, (
> > SELECT *, row_number() OVER ()
> > FROM (VALUES (23), (56), (2), (12), (10)) x) x(val,ord)
> > WHERE c.id = x.val
> > ORDER BY x.ord;
>
> Wow, that's really cool and a nice case for row_number().

Just thinking about it now; do SQL's semantics say it'll always do
the right thing? PG does in a couple of quick tests (i.e. one where
customer is a small table and PG prefers a seqscan and where it's larger
and prefers an index scan) but I'm not sure if this could change.

--
Sam http://samason.me.uk/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2010-06-02 14:56:35 Re: What Linux edition we should chose?
Previous Message Ernesto Quiñones 2010-06-02 14:53:51 Re: PosttgreSQL on AIX