From: Dawid Kuroczko <qnex42@gmail.com>
To: M.D.G. Lange <mlange@dltmedia.nl>
To: pgsql-sql@postgresql.org
Subject: Re: ORDER records based on parameters in IN clause
Date: Thu, 30 Jun 2005 09:51:35 +0200
Message-ID: <758d5e7f05063000514ece9e33@mail.gmail.com> (raw)
In-Reply-To: <42C3A0A3.40101@dltmedia.nl>
References: <BAY103-F2C56F6C371B9B2FDEEDCBB5E00@phx.gbl>
<1120057638.8208.117.camel@state.g2switchworks.com>
<42C3A0A3.40101@dltmedia.nl>
On 6/30/05, M.D.G. Lange <mlange@dltmedia.nl> wrote:
> Another option would be:
> SELECT * FROM table WHERE id=2003 OR id=1342 OR id=799 OR id=1450;
> This should give you the results in the right order...
I don't think so...
create temporary table seq as select * from generate_series(1,20) as g(id);
select * from seq where id in (5,2,12);
id
----
2
5
12
select * from seq where id = 5 or id = 2 or id = 12;
id
----
2
5
12
It certainly doesn't work.
You have to order it by something, like:
select * from seq where id in(5,2,12) order by id=5 desc,id=2 desc,id=12 desc;
id
----
5
2
12
Regards,
Dawid
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: qnex42@gmail.com, mlange@dltmedia.nl
Subject: Re: ORDER records based on parameters in IN clause
In-Reply-To: <758d5e7f05063000514ece9e33@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