Sample Header Ad - 728x90

Collate a query result column with a simple list?

2 votes
2 answers
51 views
I have many queries that return some statistical data on a subject in various tables. The result includes a "classification" that is one of {"C","P","M"}. I want the query to return the rows in the order {"M","P","C"} i.e. its is not alphabetic nor any built in collation. The data is irrelevant, but say I want to query something like a jockey's strike rate by those classifications and order the result by those codes in that order. I hope that makes sense? So, is there a way to create a Postgresql Collation that can help me or is there another way? Note there are many queries, so a complex CASE clause is not my preferred solution as I'd have to put it in every query (in every program that may even contain it's own query as a literal.
Asked by Adam Ant (23 rep)
Mar 29, 2025, 07:54 AM
Last activity: Mar 31, 2025, 01:10 PM