Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 564C29FBF63 for ; Fri, 27 Apr 2007 01:02:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 93817-06 for ; Fri, 27 Apr 2007 01:02:20 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.247]) by postgresql.org (Postfix) with ESMTP id 4F94D9FBA23 for ; Fri, 27 Apr 2007 01:02:20 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c24so496387ana for ; Thu, 26 Apr 2007 21:02:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SjfyDKyjEjmS4cYpUpp465lBzaK68wMJfUBC9rGeXsdPMPFCi+WD7G91Za2+glQIbCuC3lFIlsO5qipM9y43zzEHoNVctcDpyEKits5EYbx92ZHuvkouwIb1MQx3d3EDjd9144BrHlIeYtDgJUhBlOTO2o3HXvCRXuKQYOQ8thk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=kaQzl6N4UeVVMIr6+pqQ6/lfE6xCAONQJcJ4rYqjMcZbQtPQleSFG6ty5Jo6gaplm/TwPRwiGvWS/4SiRCWJfYm8NLN0ceF78u/gj4pIjvdTiBnKTy512TILWXcLATw8wmxYAQuN1KFNWFfIn1RLAimcPSogCmRZScn5jLgKKWk= Received: by 10.100.35.17 with SMTP id i17mr1714585ani.1177646539703; Thu, 26 Apr 2007 21:02:19 -0700 (PDT) Received: by 10.101.69.20 with HTTP; Thu, 26 Apr 2007 21:02:19 -0700 (PDT) Message-ID: Date: Fri, 27 Apr 2007 05:02:19 +0100 From: "Peter Childs" Subject: Re: Selecting rows with "static" ordering Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070427001004.B5F5D9FBABA@postgresql.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/273 X-Sequence-Number: 28273 On 27/04/07, Aaron Bono wrote: > On 4/26/07, Steve Midgley 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 > ; > could you not use the values statment of psql 8.2 hmmm select * from table, values ((1,3),(2,2),(3,5),(4,1),(5,4)) as values where values.id=table.second order by values.first; never done it but I think it should work with a bit of playing arond... Peter.