+3  A: 

Query results will be returned in non-deterministic order unless you specify an ORDER BY clause.

If you really want to do the query in the manner you are requesting, then you could construct such a clause. Here's an example using part of your data.

create table artists (
id integer not null primary key,
name char(1) not null);

insert into artists
values
    (8, 'a'),
    (1, 'b'), 
    (2, 'c'),
    (15, 'd'),
    (14, 'e'),
    (3,  'f'),
    (13, 'g');

select *
from artists
where id in (8, 1, 2, 15, 14, 3, 13)
order by
    id = 8 desc,
    id = 1 desc,
    id = 2 desc,
    id = 15 desc,
    id = 14 desc,
    id = 3 desc,
    id = 13 desc;

Based on this and on your other question, I think there is something wrong with your model or the way you are trying to do this. Perhaps you should post a more generic question about how to do what you are trying to do.

If you do have artists and ranking tables, you should be able to do something like this (or the equivalent through your ORM).

select
    a.*
from
    artists a,
    rankings r
where
    a.id = r.artist_id
order by
    r.score desc;
cope360
Thanks for your answer. I did leave a lot out about how my application works. Long story short, a ranking does not only correspond to an artist, but it can correspond to any number of object types that we give it. That said, I'm using Django's generics to create those relations which makes it a bit harder to do what I'm trying to do here.
Bryan Veloso
+2  A: 

I suggest you let PostGreSQL return the set in any arbitrary order (especially since it's difficult to do fine-grained SQL-level control from a Django interface), then sort it in the way you wish in Python -- theresultset.sort(key=yourlistofids.index) should do fine (when theresultset is the arbitrary-order list resulting from the database and yourlistofids is the list whose order you want to preserve).

Alex Martelli
Another situation where I wish I could accept both answers. :) Thank you so much, I'm going to personally take this route, but for the interest of people finding this question off of Google, I'm going to accept cope's answer.
Bryan Veloso
FWIW, I recommend against this solution. The database is designed to do sorting, whereas the app language is not. It'll be much slower than letting the database sort.
Theory
@Theory, Python is **superb** at sorting (data that fits in memory) -- its `timsort` algorithm is so splendid it's also attracted much attention e.g. in the Java world. It's absurd of you to state that (Python) "is not" "designed to do sorting" when it's so *great* at it.
Alex Martelli