From: Kevin Hunter <hunteke@earlham.edu>
To: Steve Midgley <public@misuse.org>
Cc: PostgreSQL SQL List <pgsql-sql@postgresql.org>
Subject: Re: Selecting rows with "static" ordering
Date: Fri, 27 Apr 2007 10:11:56 -0400
Message-ID: <D9565B27-E46B-498D-ACCE-6DA953DA1ADA@earlham.edu> (raw)
In-Reply-To: <20070427001004.B5F5D9FBABA@postgresql.org>
References: <20070427001004.B5F5D9FBABA@postgresql.org>
At 8:01p -0400 on 26 Apr 2007, Steve Midgley wrote:
> From that application, I want to retrieve all those rows, and I
> want them in the order they are currently stored in that variable.
> 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)
> Is there a "neat trick" that anyone knows for pulling this off in a
> single query? Basically right now I'm issuing 5 queries to the
> backend to ensure ordering but this horribly inefficient.
Why not do this particular ordering on the application side? With
this example SQL, and assuming you've PRIMARY KEYed( id ), you're
guaranteed to get a unique id for each tuple. Presumably, you've got
the order you want stored within your application, so just pull it
out of a hash in the order you need it.
Or is it terribly more complicated than this?
Kevin
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: hunteke@earlham.edu, public@misuse.org
Subject: Re: Selecting rows with "static" ordering
In-Reply-To: <D9565B27-E46B-498D-ACCE-6DA953DA1ADA@earlham.edu>
* 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