GROQ: Sort list by lowercase/case-insensitive in query?
Good news! GROQ now supports case-insensitive sorting using the lower() function. According to the GROQ Query Cheat Sheet, you can use:
*[_type == "company"] | order(lower(name) asc)This will convert all company names to lowercase for sorting purposes, so companies with all-caps abbreviations (like "ABC COMPANY") will be sorted alphabetically alongside companies with regular capitalization (like "Acme Corp"), rather than all uppercase names being placed at the beginning.
The lower() function works as an expression within the order() function, transforming the field value before sorting is applied. This solves the exact problem you're describing where uppercase letters sort before lowercase letters in standard alphabetical ordering.
So yes, this capability has been added to GROQ since those 2018-2019 discussions you found! You can now handle case-insensitive sorting directly in your query without needing to do additional sorting in your application code.
You can also combine this with multiple sort criteria if needed:
*[_type == "company"] | order(lower(name) asc, _createdAt desc)This approach keeps your sorting logic in GROQ where it belongs, making your queries more efficient and your frontend code cleaner.
Show original thread3 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.