Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ class Parser(parser.Parser):
),
"LEN": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
"LENGTH": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
"LOCALTIMESTAMP": exp.CurrentTimestamp.from_arg_list,
"NULLIFZERO": _build_if_from_nullifzero,
"OBJECT_CONSTRUCT": _build_object_construct,
"OCTET_LENGTH": exp.ByteLength.from_arg_list,
Expand Down Expand Up @@ -1464,6 +1465,9 @@ class Generator(generator.Generator):
exp.CurrentTimestamp: lambda self, e: self.func("SYSDATE")
if e.args.get("sysdate")
else self.function_fallback_sql(e),
exp.Localtimestamp: lambda self, e: self.func("CURRENT_TIMESTAMP", e.this)
if e.this
else "CURRENT_TIMESTAMP",
exp.DateAdd: date_delta_sql("DATEADD"),
exp.DateDiff: date_delta_sql("DATEDIFF"),
exp.DatetimeAdd: date_delta_sql("TIMESTAMPADD"),
Expand Down
7 changes: 7 additions & 0 deletions sqlglot/typing/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ def _annotate_str_to_time(self: TypeAnnotator, expression: exp.StrToTime) -> exp
exp.TsOrDsToTime,
}
},
**{
expr_type: {"returns": exp.DataType.Type.TIMESTAMPLTZ}
for expr_type in {
exp.CurrentTimestamp,
exp.Localtimestamp,
}
},
**{
expr_type: {"returns": exp.DataType.Type.VARCHAR}
for expr_type in {
Expand Down
2 changes: 0 additions & 2 deletions tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4741,7 +4741,6 @@ def test_localtime_and_localtimestamp(self):
"postgres": f"SELECT {func}",
"duckdb": f"SELECT {func}",
"redshift": f"SELECT {func}",
"snowflake": f"SELECT {func}",
"presto": f"SELECT {func}",
"trino": f"SELECT {func}",
"mysql": f"SELECT {func}",
Expand All @@ -4762,7 +4761,6 @@ def test_localtime_and_localtimestamp(self):
"postgres": f"SELECT {func}(2)",
"duckdb": f"SELECT {func}(2)",
"redshift": f"SELECT {func}(2)",
"snowflake": f"SELECT {func}(2)",
"presto": f"SELECT {func}(2)",
"trino": f"SELECT {func}(2)",
"mysql": f"SELECT {func}(2)",
Expand Down
3 changes: 3 additions & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,9 @@ def test_snowflake(self):
self.validate_identity("SYSDATE()")
self.validate_identity("SYSTIMESTAMP()", "CURRENT_TIMESTAMP()")
self.validate_identity("GETDATE()", "CURRENT_TIMESTAMP()")
self.validate_identity("LOCALTIMESTAMP", "CURRENT_TIMESTAMP")
self.validate_identity("LOCALTIMESTAMP()", "CURRENT_TIMESTAMP()")
self.validate_identity("LOCALTIMESTAMP(3)", "CURRENT_TIMESTAMP(3)")

def test_null_treatment(self):
self.validate_all(
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/optimizer/annotate_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,18 @@ INT;
LENGTH(tbl.bin_col);
INT;

# dialect: snowflake
LOCALTIMESTAMP;
TIMESTAMPLTZ;

# dialect: snowflake
LOCALTIMESTAMP();
TIMESTAMPLTZ;

# dialect: snowflake
LOCALTIMESTAMP(3);
TIMESTAMPLTZ;

# dialect: snowflake
OCTET_LENGTH(tbl.str_col);
INT;
Expand Down