From 7fc07f287b5ebef77ff71df1b3b27bf83b5b37f2 Mon Sep 17 00:00:00 2001 From: Jordi Enric Date: Thu, 14 May 2026 18:27:35 +0200 Subject: [PATCH] fix(unified-logs): wrap facet LIMIT subqueries in parens for UNION ALL compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClickHouse rejects a bare LIMIT clause in the middle of a UNION ALL chain — it treats LIMIT as an end-of-statement marker, so the next UNION ALL token causes a parse error. Wrapping each facet SELECT in parentheses scopes the LIMIT to that branch and satisfies the parser across all ClickHouse versions. Co-Authored-By: Claude Sonnet 4.6 --- .../interfaces/UnifiedLogs/UnifiedLogs.queries.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts index db880c26fd1..80c07aac2d4 100644 --- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts +++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts @@ -187,9 +187,7 @@ const whereClause = (predicates: SafeLogSqlFragment[]): SafeLogSqlFragment => /** * Calculates the chart bucketing level (minute/hour/day) given the date range. */ -const calculateChartBucketing = ( - search: SearchParamsType | Record -): 'MINUTE' | 'HOUR' | 'DAY' => { +const calculateChartBucketing = (search: SearchParamsType | Record): 'MINUTE' | 'HOUR' | 'DAY' => { const dateRange = (search.date as Array) || [] const convertToMillis = (timestamp: Date | string | number | null | undefined) => { @@ -317,11 +315,11 @@ export const getFacetCountQuery = ({ } return safeSql` -SELECT ${lit(facet)} AS dimension, (${facetExpr}) AS value, count() AS count +(SELECT ${lit(facet)} AS dimension, (${facetExpr}) AS value, count() AS count FROM logs ${whereClause(predicates)} GROUP BY value -LIMIT ${lit(MAX_FACETS_QUANTITY)} +LIMIT ${lit(MAX_FACETS_QUANTITY)}) ` }