X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 34CAF52A14 for ; Thu, 30 Jun 2005 04:51:46 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31190-07 for ; Thu, 30 Jun 2005 07:51:37 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.207]) by svr1.postgresql.org (Postfix) with ESMTP id 5185E52806 for ; Thu, 30 Jun 2005 04:51:36 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 8so31101nzo for ; Thu, 30 Jun 2005 00:51:35 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=pd3uUMADs+kN44jvPkQti7Ukbi29VhzSkMhkePHxidgtBrKzZ3PrKSBB7eKtZtCDKhjSgPKpgnIkz6r411mo3S1yyLcP4Zd1yPt2eg/p+xTUL0dornQTuB7N6ZakTM8+8GuT7dxkCjp8kfofae6jSWzl9ujRSLLXrmJDFmxgJBE= Received: by 10.36.222.46 with SMTP id u46mr166107nzg; Thu, 30 Jun 2005 00:51:35 -0700 (PDT) Received: by 10.36.22.20 with HTTP; Thu, 30 Jun 2005 00:51:35 -0700 (PDT) Message-ID: <758d5e7f05063000514ece9e33@mail.gmail.com> Date: Thu, 30 Jun 2005 09:51:35 +0200 From: Dawid Kuroczko Reply-To: Dawid Kuroczko To: "M.D.G. Lange" , pgsql-sql@postgresql.org Subject: Re: ORDER records based on parameters in IN clause In-Reply-To: <42C3A0A3.40101@dltmedia.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <1120057638.8208.117.camel@state.g2switchworks.com> <42C3A0A3.40101@dltmedia.nl> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.624 tagged_above=0 required=5 tests=AWL, FROM_ENDS_IN_NUMS, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/368 X-Sequence-Number: 21969 On 6/30/05, M.D.G. Lange wrote: > Another option would be: > SELECT * FROM table WHERE id=3D2003 OR id=3D1342 OR id=3D799 OR id=3D1450= ; > 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=20 ---- 2 5 12 select * from seq where id =3D 5 or id =3D 2 or id =3D 12; id=20 ---- 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=3D5 desc,id=3D2 desc,id= =3D12 desc; id=20 ---- 5 2 12 Regards, Dawid