Skip to content

Conversation

AbhishekASLK
Copy link

This PR enriches the AST by adding proper support for parsing LOCALTIME as a dedicated expression node instead of treating it as a column.

SQL:

from sqlglot import parse_one

query = """
SELECT LOCALTIME;
"""

expression = parse_one(query)
print(repr(expression))

Previously:

Select(
  expressions=[
    Column(
      this=Identifier(this=LOCALTIME, quoted=False))])

Now:

Select(
  expressions=[
    LocalTime()])

@georgesittas
Copy link
Collaborator

georgesittas commented Sep 27, 2025

What dialect supports LOCALTIME as a no-parentheses function?

@AbhishekASLK
Copy link
Author

AbhishekASLK commented Sep 27, 2025

What dialect supports LOCALTIME as a no-parentheses function?

  • MySQL
  • Snowflake
  • Postgres
  • Flink
  • Trino

we need to test for all the dialect present in sqlglot? as i only tested for 11 and from that i found these support it.

@georgesittas
Copy link
Collaborator

we need to test for all the dialect present in sqlglot? as i only tested for 11 and from that i found these support it.

We generally want to test the most common dialects, i.e.:

# yes: supports localtime, no: does not support it
Athena - yes
BigQuery - no
ClickHouse - no
Spark - no
DuckDB - yes
Oracle - no
Presto - yes
Redshift - no
Snowflake - yes
Trino - yes
mssql - no

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.

Please add tests for this PR:

  • For the dialects that don't support LOCALTIME, we should test that SELECT localtime roundtrips without being changed & that selects[0].assert_is(exp.Column)
  • For the dialects that support it, LOCALTIME should roundtrip to the supported syntax. You may need to add logic in the generator for rewriting it to LOCALTIME instead of LOCALTIME() which is the default.

arg_types = {"this": False}


class LocalTime(Func):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Func subclass names have implicit semantics. If you do LocalTime, that means the parser will recognize and produce this expression for LOCAL_TIME, not LOCALTIME.

Suggested change
class LocalTime(Func):
class Localtime(Func):

"LIMIT": TokenType.LIMIT,
"LOAD": TokenType.LOAD,
"LOCK": TokenType.LOCK,
"LOCALTIME": TokenType.LOCALTIME,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should pop this token off of KEYWORDS for BigQuery, ClickHouse, Hive (affects Spark2, Spark, Databricks– which is correct), Oracle, Redshift, T-SQL. Otherwise, we'll incorrectly produce a Localtime node instead of a Column. See this comment.

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.

2 participants