Skip to content

Commit 416122e

Browse files
type anntoation for LOCALTIMESTAMP
1 parent 7f6b9f2 commit 416122e

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ class Parser(parser.Parser):
786786
),
787787
"LEN": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
788788
"LENGTH": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
789+
"LOCALTIMESTAMP": exp.CurrentTimestamp.from_arg_list,
789790
"NULLIFZERO": _build_if_from_nullifzero,
790791
"OBJECT_CONSTRUCT": _build_object_construct,
791792
"OCTET_LENGTH": exp.ByteLength.from_arg_list,

sqlglot/typing/snowflake.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ def _annotate_str_to_time(self: TypeAnnotator, expression: exp.StrToTime) -> exp
438438
exp.TsOrDsToTime,
439439
}
440440
},
441+
**{
442+
expr_type: {"returns": exp.DataType.Type.TIMESTAMPLTZ}
443+
for expr_type in {
444+
exp.CurrentTimestamp,
445+
exp.Localtimestamp,
446+
}
447+
},
441448
**{
442449
expr_type: {"returns": exp.DataType.Type.VARCHAR}
443450
for expr_type in {

tests/dialects/test_dialect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4762,7 +4762,6 @@ def test_localtime_and_localtimestamp(self):
47624762
"postgres": f"SELECT {func}(2)",
47634763
"duckdb": f"SELECT {func}(2)",
47644764
"redshift": f"SELECT {func}(2)",
4765-
"snowflake": f"SELECT {func}(2)",
47664765
"presto": f"SELECT {func}(2)",
47674766
"trino": f"SELECT {func}(2)",
47684767
"mysql": f"SELECT {func}(2)",

tests/dialects/test_snowflake.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,8 @@ def test_snowflake(self):
21682168
self.validate_identity("SYSDATE()")
21692169
self.validate_identity("SYSTIMESTAMP()", "CURRENT_TIMESTAMP()")
21702170
self.validate_identity("GETDATE()", "CURRENT_TIMESTAMP()")
2171+
self.validate_identity("LOCALTIMESTAMP()", "CURRENT_TIMESTAMP()")
2172+
self.validate_identity("LOCALTIMESTAMP(3)", "CURRENT_TIMESTAMP(3)")
21712173

21722174
def test_null_treatment(self):
21732175
self.validate_all(

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,6 +2868,14 @@ INT;
28682868
LENGTH(tbl.bin_col);
28692869
INT;
28702870

2871+
# dialect: snowflake
2872+
LOCALTIMESTAMP();
2873+
TIMESTAMPLTZ;
2874+
2875+
# dialect: snowflake
2876+
LOCALTIMESTAMP(3);
2877+
TIMESTAMPLTZ;
2878+
28712879
# dialect: snowflake
28722880
OCTET_LENGTH(tbl.str_col);
28732881
INT;

0 commit comments

Comments
 (0)