Skip to content

Add Teradata FORMAT Clause Parsing#5348

Merged
georgesittas merged 8 commits intotobymao:mainfrom
readjfb:main
Jul 5, 2025
Merged

Add Teradata FORMAT Clause Parsing#5348
georgesittas merged 8 commits intotobymao:mainfrom
readjfb:main

Conversation

@readjfb
Copy link
Contributor

@readjfb readjfb commented Jul 3, 2025

feat(teradata): parse column format syntax
Support Teradata FORMAT column syntax

  • This PR adds parsing support and tests for the rarely used FORMAT clause in Teradata.
  • It overloads the _parse_function class in the Teradata dialect to add support for this, and adds a new FormatColumn expression
  • Adds new formatcolumn_sql method to sqlglot/expressions.py to recreate the column
  • Adds very basic testing for the FORMAT clause

My original Issue: #5325

Link to Associated Teradata Documentation

readjfb added 4 commits July 3, 2025 12:34
Support Teradata FORMAT column syntax

Add Teradata format tests

Add comments and docs for Teradata FORMAT column

Modified Comments
@readjfb
Copy link
Contributor Author

readjfb commented Jul 3, 2025

Can't figure out why this is failing - running make style and pre-commit run --all-files on my local machine is passing all tests.

@georgesittas
Copy link
Collaborator

Perhaps try nuking & recreating your venv, make install-dev and then make style?

@readjfb readjfb marked this pull request as ready for review July 3, 2025 19:09
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Can you test a few more things? E.g., do things like this work?

SELECT ('a' || 'b') (FORMAT '...')

Basically, see if a complex expression before (FORMAT ...) is valid syntax.

arg_types = {"this": True, "zone": True}


class FormatColumn(Expression):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's rename this to FormatPhrase. This applies to other things besides columns, right? E.g.:

-- (FORMAT ...) is applied to a SUM expression here
SELECT SUM(Salary) (FORMAT '$$99,999.99') FROM Employee;

Comment on lines +250 to +253
if self._match(TokenType.L_PAREN, advance=False):
index = self._index
self._match(TokenType.L_PAREN)
if self._match(TokenType.FORMAT):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self._match(TokenType.L_PAREN, advance=False):
index = self._index
self._match(TokenType.L_PAREN)
if self._match(TokenType.FORMAT):
if self._match_pair(TokenType.L_PAREN, TokenType.FORMAT):

@georgesittas georgesittas merged commit cea6a24 into tobymao:main Jul 5, 2025
7 checks passed
@georgesittas
Copy link
Collaborator

I'll take this to the finish line, seems like a small lift. Thanks for the PR!

@readjfb
Copy link
Contributor Author

readjfb commented Jul 5, 2025

Thanks for picking this up and closing out! Will look to continue contributing in the future

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.

3 participants