Skip to content

feat(parser): allow COLLATE in ORDER BY clauses (issue #2245) #2277

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ldaIas
Copy link

@ldaIas ldaIas commented Jul 10, 2025

This PR seeks to resolve this issue: #2245 (comment).

  • In the OrderByElement() JJTree rule, introduced a new Token collateToken to capture the literal or quoted identifier following COLLATE.
  • Added a lookahead for <K_COLLATE> in the grammar so that if COLLATE appears after the expression, we wrap the existing columnReference in a new CollateExpression(columnReference, collateToken.image).
  • This ensures that COLLATE 'UND-X-ICU' (or an identifier) is parsed correctly in ORDER BY clauses.

For example, the following SQL statement would fail:

select *
from a
order by cast(a.xyz as text) collate "und-x-icu" asc nulls first

with error:
Encountered unexpected token: "COLLATE" "COLLATE" at line 1, column 46. Was expecting one of: <EOF> <ST_SEMICOLON>

Now this same statement can be parsed succesfully.

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

Successfully merging this pull request may close these issues.

1 participant