fix: Support parentheses in BigQuery CAST FORMAT syntax#7395
Merged
geooo109 merged 2 commits intotobymao:mainfrom Mar 26, 2026
Merged
fix: Support parentheses in BigQuery CAST FORMAT syntax#7395geooo109 merged 2 commits intotobymao:mainfrom
geooo109 merged 2 commits intotobymao:mainfrom
Conversation
geooo109
reviewed
Mar 26, 2026
geooo109
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7390
Summary
Fixes parsing of BigQuery's
CASTwith FORMAT clause when the format string is wrapped in parentheses. BigQuery allows bothFORMAT 'YYYY'andFORMAT ('YYYY')syntax, but SQLGlot only supported the former.Problem
The parser failed with ParseError when encountering parentheses around the format string:
This worked:
CAST(date AS STRING FORMAT 'YYYY')This failed (but is valid BigQuery syntax):
CAST(date AS STRING FORMAT ('YYYY'))Error message:
ParseError: Required keyword: 'expressions' missing for <class 'sqlglot.expressions.core.Aliases'>Solution
Modified
_parse_cast()insqlglot/parser.pyto handle optional parentheses around the format string. The fix:FORMATkeywordChanges
test_cast_format_with_parentheses()with 5 test cases covering various scenariosTesting
Impact