Re: Is it possible to make the order of output the same as the order of input parameters? - Mailing list pgsql-general

From Tim Landscheidt
Subject Re: Is it possible to make the order of output the same as the order of input parameters?
Date
Msg-id m3vda1tp99.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to Is it possible to make the order of output the same as the order of input parameters?  ("m. hvostinski" <makhvost@gmail.com>)
Responses Re: Is it possible to make the order of output the same as the order of input parameters?
List pgsql-general
Sam Mason <sam@samason.me.uk> wrote:

>> >   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.

PostgreSQL's documentation on VALUES has at least no guaran-
tee of the order of data. I'd prefer David's solution :-).

Tim

pgsql-general by date:

Previous
From: Richard Broersma
Date:
Subject: Re: [NOVICE] sum multiple tables gives wrong answer?
Next
From: Peter Geoghegan
Date:
Subject: Re: server-side extension in c++