Skip to content

Treat ClickHouse range() as a function when followed by a parenthesis - #983

Open
cpruijsen wants to merge 1 commit into
sql-formatter-org:masterfrom
cpruijsen:fix/issue-980
Open

cpruijsen wants to merge 1 commit into
sql-formatter-org:masterfrom
cpruijsen:fix/issue-980

Conversation

@cpruijsen

@cpruijsen cpruijsen commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Remap ClickHouse RANGE to a function name when the next token is (. ClickHouse function names are case-sensitive. With keywordCase: "upper", SELECT range(32) stays range(32) instead of RANGE (32), which ClickHouse rejects:

Code: 46. DB::Exception: Function with name `RANGE` does not exist.
Maybe you meant: ['range','rand']. (UNKNOWN_FUNCTION)

Fixes #980.

RANGE is a reserved keyword. range() is omitted from the functions list because RANGE is also a window-frame word. postProcess already remaps SET(100) to a function name when the next token is (. RANGE now uses that same neighbour check. Default functionCase is preserve, so the original range spelling is kept.

{ROWS | RANGE} BETWEEN remains a reserved keyword phrase, so window frames are unchanged.

Alternative: add range to clickhouse.functions.ts. That would let funcNameToIdent turn bare RANGE into an identifier (for example RANGE UNBOUNDED PRECEDING) and would fight the existing comment on the functions list. Happy to switch if that is preferred.

Test plan

  • SELECT range(32) with keywordCase: "upper" keeps range(32)
  • RANGE BETWEEN in a window frame still formats as a keyword phrase
  • ClickHouse dialect tests (test/clickhouse.test.ts)

keywordCase upper was rewriting range() to RANGE (), which ClickHouse
rejects. Remap RANGE + OPEN_PAREN the same way SET(100) is remapped,
and leave RANGE BETWEEN as a window-frame keyword phrase.

This branch has not been deployed

No deployments
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.

[FORMATTING] ClickHouse: keywordCase: upper breaks the case-sensitive range() function

1 participant