Skip to content
1 change: 1 addition & 0 deletions sqlglot/dialects/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ class Generator(generator.Generator):
),
exp.UnixToTime: _unix_to_time_sql,
exp.UnixToTimeStr: lambda self, e: f"CAST(TO_TIMESTAMP({self.sql(e, 'this')}) AS TEXT)",
exp.Variance: rename_func("VAR_SAMP"),
exp.VariancePop: rename_func("VAR_POP"),
exp.WeekOfYear: rename_func("WEEKOFYEAR"),
exp.Xor: bool_xor_sql,
Expand Down
3 changes: 2 additions & 1 deletion tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def test_duckdb(self):
},
write={
"": "VARIANCE_POP(x)",
"duckdb": "VAR_POP(x)",
},
)
self.validate_all(
Expand Down Expand Up @@ -1013,7 +1014,7 @@ def test_duckdb(self):
self.validate_all(
"VARIANCE(a)",
write={
"duckdb": "VARIANCE(a)",
"duckdb": "VAR_SAMP(a)",
"clickhouse": "varSamp(a)",
},
)
Expand Down
16 changes: 16 additions & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ def test_snowflake(self):
self.validate_identity("SELECT REGR_SXY(y, x)")
self.validate_identity("SELECT REGR_SYY(y, x)")
self.validate_identity("SELECT REGR_SLOPE(y, x)")
self.validate_all(
"SELECT VAR_SAMP(x)",
write={
"snowflake": "SELECT VARIANCE(x)",
"duckdb": "SELECT VAR_SAMP(x)",
"postgres": "SELECT VAR_SAMP(x)",
},
)
self.validate_all(
"SELECT VAR_POP(x)",
write={
"snowflake": "SELECT VARIANCE_POP(x)",
"duckdb": "SELECT VAR_POP(x)",
"postgres": "SELECT VAR_POP(x)",
},
)
self.validate_all(
"SELECT SKEW(a)",
write={
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/optimizer/annotate_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4252,6 +4252,26 @@ INT;
MODE(tbl.str_col) OVER (PARTITION BY tbl.int_col);
VARCHAR;

# dialect: snowflake
VAR_SAMP(tbl.double_col);
DOUBLE;

# dialect: snowflake
VARIANCE_SAMP(tbl.double_col);
DOUBLE;

# dialect: snowflake
VARIANCE(tbl.double_col);
DOUBLE;

# dialect: snowflake
VAR_POP(tbl.double_col);
DOUBLE;

# dialect: snowflake
VARIANCE_POP(tbl.double_col);
DOUBLE;

--------------------------------------
-- T-SQL
--------------------------------------
Expand Down