A commenter suggested using enum
, and that may be best for you. You can also try adding a function at the database level that let's you do custom sorts, depending on your database. Here's a quick blog post on how you might set that up. Your sort function might look something like this (credit to blog post cited above):
CREATE OR REPLACE FUNCTION custom_sort(anyarray, anyelement)
RETURNS INT AS
$$
SELECT i FROM (
SELECT generate_series(array_lower($1,1),array_upper($1,1))
) g(i)
WHERE $1[i] = $2
LIMIT 1;
$$ LANGUAGE SQL IMMUTABLE;
This gives you a function you can call with a custom ordering, so your sort might look like this:
ORDER BY custom_sort (ARRAY['Finished', 'Active', 'Frozen'], posts.status)