: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): make rand() case-insensitive so RAND() works (#65845)
posthog[bot]6742f44b665d
diff --git a/posthog/hogql/functions/clickhouse/mathematical.py b/posthog/hogql/functions/clickhouse/mathematical.pyindex 88302cd62cb9..f3150db8302a 100644--- a/posthog/hogql/functions/clickhouse/mathematical.py+++ b/posthog/hogql/functions/clickhouse/mathematical.py@@ -57,7 +57,7 @@ ROUNDING_FUNCTIONS: dict[str, HogQLFunctionMeta] = {# Keep in sync with the posthog.com repository: contents/docs/sql/clickhouse-functions.mdxRANDOM_FUNCTIONS: dict[str, HogQLFunctionMeta] = {- "rand": HogQLFunctionMeta("rand", 0, 0),+ "rand": HogQLFunctionMeta("rand", 0, 0, case_sensitive=False),}# Combined mathematical functionsdiff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex 0e3df7f60938..0ddb59f3bd9f 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -461,6 +461,11 @@ class TestPrinter(BaseTest):self.assertEqual(self._expr("1.0 % 2.66"), "modulo(1.0, 2.66)")self.assertEqual(self._expr("'string'"), "%(hogql_val_0)s")+ def test_case_insensitive_function_name(self):+ # rand is registered case-insensitively, so uppercase RAND() resolves to rand()+ self.assertEqual(self._expr("rand()"), "rand()")+ self.assertEqual(self._expr("RAND()"), "rand()")+def test_arrays(self):self.assertEqual(self._expr("[]"), "[]")self.assertEqual(self._expr("[1,2]"), "[1, 2]")diff --git a/posthog/hogql/test/test_mapping.py b/posthog/hogql/test/test_mapping.pyindex c5c9ed5ec057..bc9efcbf33dc 100644--- a/posthog/hogql/test/test_mapping.py+++ b/posthog/hogql/test/test_mapping.py@@ -52,6 +52,7 @@ class TestMappings(ClickhouseTestMixin, BaseTest):def test_find_case_insensitive_function(self):self.assertEqual(self._get_hogql_function("CoAlesce").clickhouse_name, "coalesce")+ self.assertEqual(self._get_hogql_function("RAND").clickhouse_name, "rand")self.assertEqual(self._get_hogql_aggregation("SuM").clickhouse_name, "sum")