Enum ordering in Postgres
Rather than adhering to alphabetical order, when using order by with an enum column, the sorting adheres to the order in which the values were listed when the enum was created.
create type application_status as enum (
'submitted',
'under_review',
'accepted',
'rejected'
);
create table applications (
applicant_name text,
status application_status
);
insert into applications values
('George Washington', 'accepted'),
('John Adams', 'under_review'),
('Thomas Jefferson', 'under_review'),
('Aaron Burr', 'rejected'),
('Thomas Pinckney', 'submitted');
select * from applications order by status;
-- applicant_name | status
-- ------------------+-------------
-- Thomas Pinckney | submitted
-- John Adams | under_review
-- Thomas Jefferson | under_review
-- George Washington | accepted
-- Aaron Burr | rejected