Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROQ | order(name asc) sorts uppercase then lowercase e.g. ABGc not ABcG #167

Closed
simonhrogers opened this issue Feb 15, 2024 · 2 comments
Closed

Comments

@simonhrogers
Copy link

simonhrogers commented Feb 15, 2024

I’m not sure if this is a bug; but it’s not what I would expect personally. Is there a logic for this decision that makes sense in other contexts/cultures/languages? I’m doing in the limited context of ordering a list of ‘collaborator’ documents alphabetically. It’s important they’re alphabetised irrespective of case because some people use lowercase as a stylistic decision but you’d still expect to find them listed under ‘c’.

To be clear, current order sorted by GROQ is:

A
Akera Engineers

G
Gardiner and Theobald
Gerald Eve

C
cc|be

But I would expect:

A
Akera Engineers

C
cc|be

G
Gardiner and Theobald
Gerald Eve
@hacknug
Copy link

hacknug commented May 15, 2024

I’m not sure if this is a bug

Me neither but I think you can use global::lower() to sort the lowercase string instead.

@judofyr
Copy link
Collaborator

judofyr commented May 16, 2024

This is not a bug: The ordering is based on the Unicode codepoint and is not aware of locale or anything like that. It's maybe not the most useful behavior, but it's quite easy to reason about.

For this specific case, as @hacknug mentioned, you can use lower:

*[_type == "post"]|order(lower(title))

@judofyr judofyr closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants