Skip to content

fix(mysql): apply keywordCase to INTERVAL duration expressions - #995

Closed
emirmrkaljevic wants to merge 1 commit into
sql-formatter-org:masterfrom
emirmrkaljevic:mysql-interval-keywordcase
Closed

emirmrkaljevic wants to merge 1 commit into
sql-formatter-org:masterfrom
emirmrkaljevic:mysql-interval-keywordcase

Conversation

@emirmrkaljevic

Copy link
Copy Markdown

Fixes #985.

Problem

With language: 'mysql' and keywordCase: 'upper', interval in duration expressions (interval 30 day) stayed lowercase. The same query under mariadb uppercased it to INTERVAL.

MySQL lists INTERVAL as both a reserved keyword and a function name (INTERVAL(N, ...)). The tokenizer matches the function form first; when there is no following (, disambiguateTokens demotes it to IDENTIFIER, so keywordCase never applies.

Fix

In the shared MariaDB-like postProcess, keep INTERVAL as RESERVED_KEYWORD when it is not followed by (. Call form INTERVAL(...) stays a function name and still respects functionCase.

Tests

  • Regression for MySQL duration expressions with keywordCase: 'upper'
  • Confirms INTERVAL(...) still formats as a function

Full suite: 5887 passed, 1 skipped.

INTERVAL is listed as both a function and a keyword in MySQL-like
dialects. Without a following '(', it was demoted to IDENTIFIER, so
keywordCase left `interval 30 day` unchanged while MariaDB uppercased
it. Keep the non-call form as RESERVED_KEYWORD in the shared MariaDB
post-process path.
@nene

nene commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

I'm adopting a new policy for this repository: no AI-generated contributions. I don't care how good they are.

This is to preserve my sanity.

@nene nene closed this Oct 29, 2026
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] MySQL: INTERVAL is not affected by keywordCase (it is in MariaDB)

2 participants