pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Bono <postgresql@aranya.com>
To: Steve Midgley <public@misuse.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Selecting rows with "static" ordering
Date: Thu, 26 Apr 2007 19:46:58 -0500
Message-ID: <bf05e51c0704261746m3c6cea8dk7003e3806fd457ca@mail.gmail.com> (raw)
In-Reply-To: <20070427001004.B5F5D9FBABA@postgresql.org>
References: <20070427001004.B5F5D9FBABA@postgresql.org>

On 4/26/07, Steve Midgley <public@misuse.org> wrote:
>
> So take
> for example this foreign application variable:
>
>    ids = "3,2,5,1,4"
>
> The application then executes this sql:
>
>    select * from table where id in (3,2,5,1,4)
>
> As-is, of course, the above query will return the 5 records in a
> semi-random (i.e. unpredictable/unreliable) order. And I don't want to
> just "order by id" - I want to "order by id(3,2,5,1,4)" (if you see
> what I mean)
>
>
select *
from table
where id in (3, 2, 5, 1, 4)
order by
    case when (id = 3) then 1
    when (id = 2) then 2
    when (id = 5) then 3
    when (id = 1) then 4
    when (id = 4) then 5
    else null
    end
;

-- 
==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
==================================================================

view thread (6+ messages)  latest in thread

Message-ID: <bf05e51c0704261746m3c6cea8dk7003e3806fd457ca@mail.gmail.com>
Permalink:  ../bf05e51c0704261746m3c6cea8dk7003e3806fd457ca@mail.gmail.com/
Also on:    postgresql.org/message-id/bf05e51c0704261746m3c6cea8dk7003e3806fd457ca@mail.gmail.com

 · 

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: postgresql@aranya.com, public@misuse.org
  Subject: Re: Selecting rows with "static" ordering
  In-Reply-To: <bf05e51c0704261746m3c6cea8dk7003e3806fd457ca@mail.gmail.com>

* 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