Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): Handle snowflake identifiers when they're lowercase (#60944)

Kyle Swank0edc16d8d9f7
diff --git a/posthog/temporal/data_imports/sources/snowflake/snowflake.py b/posthog/temporal/data_imports/sources/snowflake/snowflake.py
index 67f7e3ce1c46..4170afd5e961 100644
--- a/posthog/temporal/data_imports/sources/snowflake/snowflake.py
+++ b/posthog/temporal/data_imports/sources/snowflake/snowflake.py
@@ -90,13 +90,12 @@ def _build_query(
db_incremental_field_last_value = incremental_type_to_initial_value(incremental_field_type)
operator = incremental_type_to_operator(incremental_field_type)
+ quoted_field = _SNOWFLAKE_IDENTIFIER_QUOTER.quote(incremental_field)
return (
- f"SELECT {select_clause} FROM IDENTIFIER(%s) WHERE IDENTIFIER(%s) {operator} %s ORDER BY IDENTIFIER(%s) ASC",
+ f"SELECT {select_clause} FROM IDENTIFIER(%s) WHERE {quoted_field} {operator} %s ORDER BY {quoted_field} ASC",
(
f"{database}.{schema}.{table_name}",
- incremental_field,
db_incremental_field_last_value,
- incremental_field,
),
)
diff --git a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index a2ae94aed639..4375b30d9989 100644
--- a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -136,14 +136,14 @@ class TestBuildQuery:
def test_incremental_uses_operator_and_orders(self):
sql, params = _build_query("DB", "PUBLIC", "t", True, "created_at", IncrementalFieldType.DateTime, "2025-01-01")
- assert "WHERE IDENTIFIER(%s)" in sql
- assert "ORDER BY IDENTIFIER(%s) ASC" in sql
- assert params == ("DB.PUBLIC.t", "created_at", "2025-01-01", "created_at")
+ assert 'WHERE "created_at"' in sql
+ assert 'ORDER BY "created_at" ASC' in sql
+ assert params == ("DB.PUBLIC.t", "2025-01-01")
def test_incremental_seeds_initial_value_when_missing(self):
# None last-value triggers fallback to incremental_type_to_initial_value
_, params = _build_query("DB", "PUBLIC", "t", True, "created_at", IncrementalFieldType.DateTime, None)
- assert params[2] is not None
+ assert params[1] is not None
class TestBuildQueryEnabledColumns:
@@ -185,8 +185,9 @@ class TestBuildQueryEnabledColumns:
primary_keys=["ID"],
)
assert sql.startswith('SELECT "EMAIL", "ID", "CREATED_AT" FROM IDENTIFIER(%s)')
- assert "WHERE IDENTIFIER(%s)" in sql
- assert params == ("DB.PUBLIC.t", "CREATED_AT", "2025-01-01", "CREATED_AT")
+ assert 'WHERE "CREATED_AT"' in sql
+ assert 'ORDER BY "CREATED_AT" ASC' in sql
+ assert params == ("DB.PUBLIC.t", "2025-01-01")
# ---------------------------------------------------------------------------