Skip to content

Commit 3905b90

Browse files
updated testing
1 parent 8c442dd commit 3905b90

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,9 @@ class Generator(generator.Generator):
14651465
exp.CurrentTimestamp: lambda self, e: self.func("SYSDATE")
14661466
if e.args.get("sysdate")
14671467
else self.function_fallback_sql(e),
1468+
exp.Localtimestamp: lambda self, e: self.func("CURRENT_TIMESTAMP", e.this)
1469+
if e.this
1470+
else "CURRENT_TIMESTAMP",
14681471
exp.DateAdd: date_delta_sql("DATEADD"),
14691472
exp.DateDiff: date_delta_sql("DATEDIFF"),
14701473
exp.DatetimeAdd: date_delta_sql("TIMESTAMPADD"),

tests/dialects/test_dialect.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,10 +4751,16 @@ def test_localtime_and_localtimestamp(self):
47514751
if func == "LOCALTIMESTAMP":
47524752
dialects["oracle"] = f"SELECT {func}"
47534753

4754+
write_dialects = dialects.copy()
4755+
4756+
if func == "LOCALTIMESTAMP":
4757+
del dialects["snowflake"]
4758+
write_dialects["snowflake"] = "SELECT CURRENT_TIMESTAMP"
4759+
47544760
self.validate_all(
47554761
f"SELECT {func}",
47564762
read=dialects,
4757-
write=dialects,
4763+
write=write_dialects,
47584764
)
47594765

47604766
with self.subTest(f"Testing {func} with precision"):
@@ -4763,18 +4769,24 @@ def test_localtime_and_localtimestamp(self):
47634769
"duckdb": f"SELECT {func}(2)",
47644770
"redshift": f"SELECT {func}(2)",
47654771
"presto": f"SELECT {func}(2)",
4772+
"snowflake": f"SELECT {func}(2)",
47664773
"trino": f"SELECT {func}(2)",
47674774
"mysql": f"SELECT {func}(2)",
47684775
"singlestore": f"SELECT {func}(2)",
47694776
}
47704777

47714778
if func == "LOCALTIMESTAMP":
47724779
dialects["oracle"] = f"SELECT {func}(2)"
4780+
write_dialects = dialects.copy()
4781+
4782+
if func == "LOCALTIMESTAMP":
4783+
del dialects["snowflake"]
4784+
write_dialects["snowflake"] = "SELECT CURRENT_TIMESTAMP(2)"
47734785

47744786
self.validate_all(
47754787
f"SELECT {func}(2)",
47764788
read=dialects,
4777-
write=dialects,
4789+
write=write_dialects,
47784790
)
47794791

47804792
exp_type = exp.Localtime if func == "LOCALTIME" else exp.Localtimestamp

tests/dialects/test_snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ def test_snowflake(self):
21702170
self.validate_identity("SYSDATE()")
21712171
self.validate_identity("SYSTIMESTAMP()", "CURRENT_TIMESTAMP()")
21722172
self.validate_identity("GETDATE()", "CURRENT_TIMESTAMP()")
2173+
self.validate_identity("LOCALTIMESTAMP", "CURRENT_TIMESTAMP")
21732174
self.validate_identity("LOCALTIMESTAMP()", "CURRENT_TIMESTAMP()")
21742175
self.validate_identity("LOCALTIMESTAMP(3)", "CURRENT_TIMESTAMP(3)")
21752176

0 commit comments

Comments
 (0)