Repository: tobymao/sqlglot

Issue:
APPROX_PERCENTILE is translated from Trino to APPROX_QUANTILE in Snowflake, which does not exist in Snowflake
**Fully reproducible code snippet**
```
>>> sql = "SELECT APPROX_PERCENTILE(a,1, 0.5, 0.001) from t"
>>> select = sqlglot.parse_one(sql, "trino")
>>> select.sql("snowflake")
'SELECT APPROX_QUANTILE(a, 0.5, 0.001, 1) FROM t'
```
It should be translated to `APPROX_PERCENTILE`

**Official Documentation**
https://docs.snowflake.com/en/sql-reference/functions/approx_percentile


Discussion:

Patch:
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index 5a45215b..538cb9cb 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -345,6 +345,7 @@ class Snowflake(Dialect):
 
         FUNCTIONS = {
             **parser.Parser.FUNCTIONS,
+            "APPROX_PERCENTILE": exp.ApproxQuantile.from_arg_list,
             "ARRAYAGG": exp.ArrayAgg.from_arg_list,
             "ARRAY_CONSTRUCT": exp.Array.from_arg_list,
             "ARRAY_CONTAINS": lambda args: exp.ArrayContains(
@@ -1051,3 +1052,11 @@ class Snowflake(Dialect):
                 return f"{option} = ({values})"
 
             return super().copyparameter_sql(expression)
+
+        def approxquantile_sql(self, expression: exp.ApproxQuantile) -> str:
+            if expression.args.get("weight") or expression.args.get("accuracy"):
+                self.unsupported(
+                    "APPROX_PERCENTILE with weight and/or accuracy arguments are not supported in Snowflake"
+                )
+
+            return self.func("APPROX_PERCENTILE", expression.this, expression.args.get("quantile"))


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 62fa5974..d03412ca 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -832,6 +832,18 @@ WHERE
                 "snowflake": "SELECT LISTAGG(col1, ', ') WITHIN GROUP (ORDER BY col2) FROM t",
             },
         )
+        self.validate_all(
+            "SELECT APPROX_PERCENTILE(a, 0.5) FROM t",
+            read={
+                "trino": "SELECT APPROX_PERCENTILE(a, 1, 0.5, 0.001) FROM t",
+                "presto": "SELECT APPROX_PERCENTILE(a, 1, 0.5, 0.001) FROM t",
+            },
+            write={
+                "trino": "SELECT APPROX_PERCENTILE(a, 0.5) FROM t",
+                "presto": "SELECT APPROX_PERCENTILE(a, 0.5) FROM t",
+                "snowflake": "SELECT APPROX_PERCENTILE(a, 0.5) FROM t",
+            },
+        )
 
     def test_null_treatment(self):
         self.validate_all(