Repository: tobymao/sqlglot

Issue:
Incorrect `SHA` Function Mapping for DuckDB Dialect in SQLGlot
When testing SQLGlot with DuckDB, the `SHA` function is incorrectly translated. The expected function name in DuckDB is `SHA1`, but it gets mapped to `SHA` instead.

#### Original Query:

```sql
SELECT sha1(?::VARCHAR) LIMIT 1
```

#### SQLGlot Output (DuckDB Dialect):

```sql
SELECT SHA(CAST(? AS TEXT)) LIMIT 1
```

#### Expected Behavior:
The function should be translated as `SHA1` in DuckDB, matching the original query.

Discussion:
@georgesittas: Fixed by #4191 -- thanks!

Solution patch:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index 3932c11bc4..467152fb1e 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -549,6 +549,7 @@ class Generator(generator.Generator):
             exp.ReturnsProperty: lambda self, e: "TABLE" if isinstance(e.this, exp.Schema) else "",
             exp.Rand: rename_func("RANDOM"),
             exp.SafeDivide: no_safe_divide_sql,
+            exp.SHA: rename_func("SHA1"),
             exp.SHA2: sha256_sql,
             exp.Split: rename_func("STR_SPLIT"),
             exp.SortArray: _sort_array_sql,


Test patch:
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index f6a00547c0..883c667287 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -973,6 +973,15 @@ def test_time(self):
                 "spark": "DATE_FORMAT(x, 'yy-M-ss')",
             },
         )
+
+        self.validate_all(
+            "SHA1(x)",
+            write={
+                "duckdb": "SHA1(x)",
+                "": "SHA(x)",
+            },
+        )
+
         self.validate_all(
             "STRFTIME(x, '%Y-%m-%d %H:%M:%S')",
             write={