Skip to content

feat(insights): hint to alias SQL breakdown expressions#55405

Merged
rafaeelaudibert merged 2 commits intomasterfrom
posthog-code/sql-breakdown-label-hint
Apr 21, 2026
Merged

feat(insights): hint to alias SQL breakdown expressions#55405
rafaeelaudibert merged 2 commits intomasterfrom
posthog-code/sql-breakdown-label-hint

Conversation

@posthog
Copy link
Copy Markdown
Contributor

@posthog posthog Bot commented Apr 20, 2026

Problem

On an insight breakdown, if a user picks the SQL expression option and enters a non-trivial expression (e.g. countIf(properties.$browser = 'Chrome')), the raw expression is used verbatim as the column/series label. That's unreadable in charts and tables. Today, a user can work around this by aliasing the expression — either with AS column_name or with a trailing -- column_name comment — but there's no in-product hint that this is an option.

Context: support ticket #335.

Changes

  • Added a showBreakdownLabelHint prop to HogQLEditor. When set, and the current buffered expression is longer than 20 characters and doesn't already end in an AS <name> alias or contain a -- <name> comment label, a small secondary-text tip is rendered directly under the editor hint:

    Tip: add AS column_name or -- column_name to the end of your expression to use a readable label for this breakdown.

  • Threaded the flag from TaxonomicFiltertaxonomicFilterLogic → the HogQL expression group's componentPropsInlineHogQLEditorHogQLEditor, so the hint can be opted into per TaxonomicFilter usage.

  • Set hogQLExpressionShowBreakdownLabelHint on the TaxonomicFilter rendered from TaxonomicBreakdownPopover, so the hint only appears in the insights breakdown flow (not in property filters, column selectors, etc., which also use the same editor).

  • Combined the new prop with hogQLGlobals into a single hogQLExpressionComponentProps selector to stay within kea's SelectorTuple length limit on the taxonomicGroups selector.

How did you test this code?

  • pnpm --filter=@posthog/frontend typescript:check reports the same number of pre-existing errors before and after this change (no new TS errors introduced).
  • pnpm --filter=@posthog/frontend format runs cleanly.
  • No manual browser test performed in this agent environment — the dev server wasn't started, so the UI change itself has not been interactively verified. Reviewers should spot-check the breakdown popover with short (<= 20 char) expressions, long expressions, and long expressions that already use AS or -- name.

Publish to changelog?

no

🤖 LLM context

Authored by PostHog Code based on a Slack request to surface the AS column_name / -- column_name workaround as an in-product hint on SQL breakdowns, gated on expression length > 20 characters.


Created with PostHog Code

When a user enters a long SQL expression in the taxonomic filter's SQL
expression tab while configuring an insight breakdown, the raw expression
shows up verbatim as the column/series label — often unreadable.

Show a short tip in the editor — only when the expression is longer than
20 characters and doesn't already contain an `AS name` alias or a trailing
`-- name` comment — pointing to either workaround to get a readable label.

Generated-By: PostHog Code
Task-Id: 96d340a8-be92-4f3b-9e65-9fc7a74fe3b9
@rafaeelaudibert rafaeelaudibert self-requested a review April 20, 2026 22:34
@rafaeelaudibert rafaeelaudibert marked this pull request as ready for review April 20, 2026 22:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Size Change: +2.44 kB (0%)

Total Size: 129 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/368Hedgehogs 5.26 kB 0 B
frontend/dist/abap 14.2 kB 0 B
frontend/dist/AccountSocialConnected 2.17 kB 0 B
frontend/dist/Action 23.9 kB 0 B
frontend/dist/Actions 1.02 kB 0 B
frontend/dist/AdvancedActivityLogsScene 35.6 kB 0 B
frontend/dist/AgenticAuthorize 5.25 kB 0 B
frontend/dist/apex 3.95 kB 0 B
frontend/dist/ApprovalDetail 16.2 kB 0 B
frontend/dist/array.full.es5.js 333 kB 0 B
frontend/dist/array.full.js 427 kB 0 B
frontend/dist/array.js 183 kB 0 B
frontend/dist/AsyncMigrations 13.1 kB 0 B
frontend/dist/AuthorizationStatus 716 B 0 B
frontend/dist/azcli 846 B 0 B
frontend/dist/bat 1.84 kB 0 B
frontend/dist/BatchExportScene 60.5 kB 0 B
frontend/dist/bicep 2.55 kB 0 B
frontend/dist/Billing 493 B 0 B
frontend/dist/BillingSection 20.8 kB 0 B
frontend/dist/BoxPlot 5.04 kB 0 B
frontend/dist/browserAll-0QZMN1W2 37.4 kB 0 B
frontend/dist/ButtonPrimitives 562 B 0 B
frontend/dist/CalendarHeatMap 4.79 kB 0 B
frontend/dist/cameligo 2.18 kB 0 B
frontend/dist/changeRequestsLogic 544 B 0 B
frontend/dist/CLIAuthorize 11.3 kB 0 B
frontend/dist/CLILive 3.97 kB 0 B
frontend/dist/clojure 9.64 kB 0 B
frontend/dist/coffee 3.59 kB 0 B
frontend/dist/Cohort 24.8 kB 0 B
frontend/dist/CohortCalculationHistory 6.22 kB 0 B
frontend/dist/Cohorts 9.39 kB 0 B
frontend/dist/ConfirmOrganization 4.48 kB 0 B
frontend/dist/conversations.js 65.8 kB 0 B
frontend/dist/Coupons 720 B 0 B
frontend/dist/cpp 5.3 kB 0 B
frontend/dist/Create 829 B 0 B
frontend/dist/crisp-chat-integration.js 1.88 kB 0 B
frontend/dist/csharp 4.52 kB 0 B
frontend/dist/csp 1.42 kB 0 B
frontend/dist/css 4.51 kB 0 B
frontend/dist/cssMode 4.15 kB 0 B
frontend/dist/CustomCssScene 3.55 kB 0 B
frontend/dist/CustomerAnalyticsConfigurationScene 1.99 kB 0 B
frontend/dist/CustomerAnalyticsScene 26.4 kB 0 B
frontend/dist/CustomerJourneyBuilderScene 1.69 kB 0 B
frontend/dist/CustomerJourneyTemplatesScene 7.39 kB 0 B
frontend/dist/customizations.full.js 17.9 kB 0 B
frontend/dist/CyclotronJobInputAssignee 1.32 kB 0 B
frontend/dist/CyclotronJobInputBusinessHours 2.71 kB 0 B
frontend/dist/CyclotronJobInputTicketTags 711 B 0 B
frontend/dist/cypher 3.38 kB 0 B
frontend/dist/dart 4.25 kB 0 B
frontend/dist/Dashboard 1.11 kB 0 B
frontend/dist/Dashboards 24.1 kB 0 B
frontend/dist/DataManagementScene 646 B 0 B
frontend/dist/DataPipelinesNewScene 2.32 kB 0 B
frontend/dist/DataWarehouseScene 1.21 kB -50 B (-3.97%)
frontend/dist/Deactivated 1.13 kB 0 B
frontend/dist/dead-clicks-autocapture.js 13.1 kB 0 B
frontend/dist/DeadLetterQueue 5.38 kB 0 B
frontend/dist/DebugScene 20 kB 0 B
frontend/dist/decompressionWorker 2.85 kB 0 B
frontend/dist/decompressionWorker.js 2.85 kB 0 B
frontend/dist/DefinitionEdit 7.11 kB 0 B
frontend/dist/DefinitionView 22.7 kB 0 B
frontend/dist/DestinationsScene 2.71 kB 0 B
frontend/dist/dist 575 B 0 B
frontend/dist/dockerfile 1.87 kB 0 B
frontend/dist/EarlyAccessFeature 753 B 0 B
frontend/dist/EarlyAccessFeatures 2.84 kB 0 B
frontend/dist/ecl 5.33 kB 0 B
frontend/dist/EditorScene 891 B 0 B
frontend/dist/elixir 10.3 kB 0 B
frontend/dist/elk.bundled 1.44 MB 0 B
frontend/dist/EmailMFAVerify 2.98 kB 0 B
frontend/dist/EndpointScene 37.5 kB 0 B
frontend/dist/EndpointsScene 22.1 kB 0 B
frontend/dist/ErrorTrackingIssueFingerprintsScene 6.98 kB 0 B
frontend/dist/ErrorTrackingIssueScene 95.6 kB 0 B
frontend/dist/ErrorTrackingScene 22.6 kB 0 B
frontend/dist/EvaluationTemplates 575 B 0 B
frontend/dist/EventsScene 2.57 kB 0 B
frontend/dist/exception-autocapture.js 11.8 kB 0 B
frontend/dist/Experiment 217 kB 0 B
frontend/dist/Experiments 17.7 kB 0 B
frontend/dist/exporter 20.9 MB 0 B
frontend/dist/exporter.js 20.9 MB +843 B (0%)
frontend/dist/ExportsScene 3.98 kB 0 B
frontend/dist/FeatureFlag 128 kB 0 B
frontend/dist/FeatureFlags 606 B 0 B
frontend/dist/FeatureFlagTemplatesScene 7.03 kB 0 B
frontend/dist/FlappyHog 5.78 kB 0 B
frontend/dist/flow9 1.8 kB 0 B
frontend/dist/freemarker2 16.7 kB 0 B
frontend/dist/fsharp 2.98 kB 0 B
frontend/dist/go 2.65 kB 0 B
frontend/dist/graphql 2.26 kB 0 B
frontend/dist/Group 14.4 kB 0 B
frontend/dist/Groups 3.91 kB 0 B
frontend/dist/GroupsNew 7.34 kB 0 B
frontend/dist/handlebars 7.34 kB 0 B
frontend/dist/hcl 3.59 kB 0 B
frontend/dist/HealthCategoryDetailScene 7.23 kB 0 B
frontend/dist/HealthScene 10.6 kB 0 B
frontend/dist/HeatmapNewScene 4.16 kB 0 B
frontend/dist/HeatmapRecordingScene 3.92 kB 0 B
frontend/dist/HeatmapScene 5.88 kB 0 B
frontend/dist/HeatmapsScene 3.88 kB 0 B
frontend/dist/hls 394 kB 0 B
frontend/dist/HogFunctionScene 58.8 kB 0 B
frontend/dist/HogRepl 7.37 kB 0 B
frontend/dist/html 5.58 kB 0 B
frontend/dist/htmlMode 4.62 kB 0 B
frontend/dist/image-blob-reduce.esm 49.4 kB 0 B
frontend/dist/InboxScene 59.8 kB 0 B
frontend/dist/index 302 kB 0 B
frontend/dist/index.js 302 kB 0 B
frontend/dist/ini 1.1 kB 0 B
frontend/dist/InsightQuickStart 5.42 kB 0 B
frontend/dist/InsightScene 28.9 kB 0 B
frontend/dist/IntegrationsRedirect 733 B 0 B
frontend/dist/intercom-integration.js 1.93 kB 0 B
frontend/dist/InviteSignup 14.4 kB 0 B
frontend/dist/java 3.22 kB 0 B
frontend/dist/javascript 985 B 0 B
frontend/dist/jsonMode 13.9 kB 0 B
frontend/dist/julia 7.22 kB 0 B
frontend/dist/kotlin 3.4 kB 0 B
frontend/dist/lazy 158 kB 0 B
frontend/dist/LegacyPluginScene 26.6 kB 0 B
frontend/dist/LemonTextAreaMarkdown 502 B 0 B
frontend/dist/less 3.9 kB 0 B
frontend/dist/lexon 2.44 kB 0 B
frontend/dist/lib 2.22 kB 0 B
frontend/dist/Link 468 B 0 B
frontend/dist/LinkScene 24.8 kB 0 B
frontend/dist/LinksScene 4.19 kB 0 B
frontend/dist/liquid 4.53 kB 0 B
frontend/dist/LiveDebugger 19.1 kB 0 B
frontend/dist/LiveEventsTable 3.22 kB 0 B
frontend/dist/LLMAnalyticsClusterScene 15.7 kB 0 B
frontend/dist/LLMAnalyticsClustersScene 43.1 kB 0 B
frontend/dist/LLMAnalyticsDatasetScene 19.7 kB 0 B
frontend/dist/LLMAnalyticsDatasetsScene 3.28 kB 0 B
frontend/dist/LLMAnalyticsEvaluation 58.7 kB 0 B
frontend/dist/LLMAnalyticsEvaluationsScene 29.8 kB 0 B
frontend/dist/LLMAnalyticsPlaygroundScene 36.3 kB 0 B
frontend/dist/LLMAnalyticsScene 118 kB 0 B
frontend/dist/LLMAnalyticsSessionScene 13.4 kB 0 B
frontend/dist/LLMAnalyticsTraceScene 129 kB 0 B
frontend/dist/LLMAnalyticsUsers 526 B 0 B
frontend/dist/LLMASessionFeedbackDisplay 4.83 kB 0 B
frontend/dist/LLMPromptScene 17.5 kB 0 B
frontend/dist/LLMPromptsScene 4.47 kB 0 B
frontend/dist/LLMSkillScene 589 B 0 B
frontend/dist/LLMSkillsScene 606 B 0 B
frontend/dist/Login 8.57 kB 0 B
frontend/dist/Login2FA 4.2 kB 0 B
frontend/dist/logs.js 38.5 kB 0 B
frontend/dist/LogsScene 11.4 kB 0 B
frontend/dist/lua 2.11 kB 0 B
frontend/dist/m3 2.81 kB 0 B
frontend/dist/main 819 kB 0 B
frontend/dist/ManagedMigration 14.1 kB 0 B
frontend/dist/markdown 3.79 kB 0 B
frontend/dist/MarketingAnalyticsScene 39.7 kB 0 B
frontend/dist/MaterializedColumns 10.2 kB 0 B
frontend/dist/Max 801 B 0 B
frontend/dist/mdx 5.39 kB 0 B
frontend/dist/memlens.lib.bundle 27.8 kB 0 B
frontend/dist/MessageTemplate 16.3 kB 0 B
frontend/dist/MetricsScene 828 B 0 B
frontend/dist/mips 2.58 kB 0 B
frontend/dist/ModelsScene 13.6 kB 0 B
frontend/dist/MonacoDiffEditor 403 B 0 B
frontend/dist/monacoEditorWorker 288 kB 0 B
frontend/dist/monacoEditorWorker.js 288 kB 0 B
frontend/dist/monacoJsonWorker 419 kB 0 B
frontend/dist/monacoJsonWorker.js 419 kB 0 B
frontend/dist/monacoTsWorker 7.02 MB 0 B
frontend/dist/monacoTsWorker.js 7.02 MB 0 B
frontend/dist/MoveToPostHogCloud 4.46 kB 0 B
frontend/dist/msdax 4.91 kB 0 B
frontend/dist/mysql 11.3 kB 0 B
frontend/dist/NavTabChat 4.68 kB 0 B
frontend/dist/NewSourceScene 783 B 0 B
frontend/dist/NewTabScene 647 B 0 B
frontend/dist/NodeDetailScene 16.3 kB 0 B
frontend/dist/NotebookCanvasScene 3.16 kB 0 B
frontend/dist/NotebookPanel 5.14 kB 0 B
frontend/dist/NotebookScene 8.17 kB 0 B
frontend/dist/NotebooksScene 7.58 kB 0 B
frontend/dist/OAuthAuthorize 573 B 0 B
frontend/dist/objective-c 2.41 kB 0 B
frontend/dist/Onboarding 734 kB 0 B
frontend/dist/OnboardingCouponRedemption 1.2 kB 0 B
frontend/dist/pascal 2.99 kB 0 B
frontend/dist/pascaligo 2 kB 0 B
frontend/dist/passkeyLogic 484 B 0 B
frontend/dist/PasswordReset 4.32 kB 0 B
frontend/dist/PasswordResetComplete 2.94 kB 0 B
frontend/dist/PendingDeletion 2.21 kB 0 B
frontend/dist/perl 8.25 kB 0 B
frontend/dist/PersonScene 16 kB 0 B
frontend/dist/PersonsScene 4.68 kB 0 B
frontend/dist/pgsql 13.5 kB 0 B
frontend/dist/php 8.02 kB 0 B
frontend/dist/PipelineStatusScene 9.1 kB 0 B
frontend/dist/pla 1.67 kB 0 B
frontend/dist/posthog 144 kB 0 B
frontend/dist/postiats 7.86 kB 0 B
frontend/dist/powerquery 16.9 kB 0 B
frontend/dist/powershell 3.27 kB 0 B
frontend/dist/PreflightCheck 5.53 kB 0 B
frontend/dist/product-tours.js 115 kB 0 B
frontend/dist/ProductTour 273 kB 0 B
frontend/dist/ProductTours 4.68 kB 0 B
frontend/dist/ProjectHomepage 24.7 kB 0 B
frontend/dist/protobuf 9.05 kB 0 B
frontend/dist/pug 4.82 kB 0 B
frontend/dist/python 4.76 kB 0 B
frontend/dist/qsharp 3.19 kB 0 B
frontend/dist/QueryPerformance 6.63 kB 0 B
frontend/dist/r 3.12 kB 0 B
frontend/dist/razor 9.35 kB 0 B
frontend/dist/recorder-v2.js 111 kB 0 B
frontend/dist/recorder.js 111 kB 0 B
frontend/dist/redis 3.55 kB 0 B
frontend/dist/redshift 11.8 kB 0 B
frontend/dist/RegionMap 29.4 kB 0 B
frontend/dist/render-query 20.6 MB 0 B
frontend/dist/render-query.js 20.6 MB +841 B (0%)
frontend/dist/ResourceTransfer 9.17 kB 0 B
frontend/dist/restructuredtext 3.9 kB 0 B
frontend/dist/RevenueAnalyticsScene 25.6 kB 0 B
frontend/dist/ruby 8.5 kB 0 B
frontend/dist/rust 4.16 kB 0 B
frontend/dist/SavedInsights 664 B 0 B
frontend/dist/sb 1.82 kB 0 B
frontend/dist/scala 7.32 kB 0 B
frontend/dist/scheme 1.76 kB 0 B
frontend/dist/scss 6.41 kB 0 B
frontend/dist/SdkDoctorScene 9.4 kB 0 B
frontend/dist/SessionAttributionExplorerScene 6.62 kB 0 B
frontend/dist/SessionGroupSummariesTable 4.62 kB 0 B
frontend/dist/SessionGroupSummaryScene 17 kB 0 B
frontend/dist/SessionProfileScene 15 kB 0 B
frontend/dist/SessionRecordingDetail 1.75 kB 0 B
frontend/dist/SessionRecordingFilePlaybackScene 4.46 kB 0 B
frontend/dist/SessionRecordings 742 B 0 B
frontend/dist/SessionRecordingsKiosk 8.84 kB 0 B
frontend/dist/SessionRecordingsPlaylistScene 4.14 kB 0 B
frontend/dist/SessionRecordingsSettingsScene 1.9 kB 0 B
frontend/dist/SessionsScene 3.98 kB 0 B
frontend/dist/SettingsScene 2.98 kB 0 B
frontend/dist/SharedMetric 4.83 kB 0 B
frontend/dist/SharedMetrics 549 B 0 B
frontend/dist/shell 3.07 kB 0 B
frontend/dist/SignupContainer 25.7 kB 0 B
frontend/dist/Site 1.18 kB 0 B
frontend/dist/solidity 18.6 kB 0 B
frontend/dist/sophia 2.76 kB 0 B
frontend/dist/SourceScene 758 B 0 B
frontend/dist/SourcesScene 6.08 kB 0 B
frontend/dist/sparql 2.55 kB 0 B
frontend/dist/sql 10.3 kB 0 B
frontend/dist/SqlVariableEditScene 7.24 kB 0 B
frontend/dist/st 7.4 kB 0 B
frontend/dist/StartupProgram 21.2 kB 0 B
frontend/dist/SubscriptionScene 12.8 kB 0 B
frontend/dist/SubscriptionsScene 4.89 kB 0 B
frontend/dist/SupportSettingsScene 1.16 kB 0 B
frontend/dist/SupportTicketScene 24.6 kB 0 B
frontend/dist/SupportTicketsScene 733 B 0 B
frontend/dist/Survey 848 B 0 B
frontend/dist/SurveyFormBuilder 1.54 kB 0 B
frontend/dist/Surveys 18.2 kB 0 B
frontend/dist/surveys.js 90 kB 0 B
frontend/dist/SurveyWizard 64.3 kB 0 B
frontend/dist/swift 5.26 kB 0 B
frontend/dist/SystemStatus 16.8 kB 0 B
frontend/dist/systemverilog 7.61 kB 0 B
frontend/dist/TaskDetailScene 21.5 kB 0 B
frontend/dist/TaskTracker 13.2 kB 0 B
frontend/dist/tcl 3.57 kB 0 B
frontend/dist/TextCardMarkdownEditor 11 kB 0 B
frontend/dist/toolbar 10.6 MB 0 B
frontend/dist/toolbar.js 10.6 MB +802 B (+0.01%)
frontend/dist/ToolbarLaunch 2.52 kB 0 B
frontend/dist/tracing-headers.js 1.74 kB 0 B
frontend/dist/TracingScene 29.8 kB 0 B
frontend/dist/TransformationsScene 1.95 kB 0 B
frontend/dist/tsMode 24 kB 0 B
frontend/dist/twig 5.97 kB 0 B
frontend/dist/TwoFactorReset 3.98 kB 0 B
frontend/dist/typescript 240 B 0 B
frontend/dist/typespec 2.82 kB 0 B
frontend/dist/Unsubscribe 1.62 kB 0 B
frontend/dist/UserInterview 4.53 kB 0 B
frontend/dist/UserInterviews 2.01 kB 0 B
frontend/dist/vb 5.79 kB 0 B
frontend/dist/VercelConnect 4.95 kB 0 B
frontend/dist/VercelLinkError 1.91 kB 0 B
frontend/dist/VerifyEmail 4.48 kB 0 B
frontend/dist/vimMode 211 kB 0 B
frontend/dist/VisualReviewRunScene 26.7 kB 0 B
frontend/dist/VisualReviewRunsScene 6.12 kB 0 B
frontend/dist/VisualReviewSettingsScene 10.8 kB 0 B
frontend/dist/web-vitals.js 6.39 kB 0 B
frontend/dist/WebAnalyticsScene 5.77 kB 0 B
frontend/dist/WebGLRenderer-DYjOwNoG 60.3 kB 0 B
frontend/dist/WebGPURenderer-B_wkl_Ja 36.3 kB 0 B
frontend/dist/WebScriptsScene 2.57 kB 0 B
frontend/dist/webworkerAll-puPV1rBA 324 B 0 B
frontend/dist/wgsl 7.34 kB 0 B
frontend/dist/Wizard 4.45 kB 0 B
frontend/dist/WorkflowScene 101 kB 0 B
frontend/dist/WorkflowsScene 58.3 kB 0 B
frontend/dist/WorldMap 4.73 kB 0 B
frontend/dist/xml 2.98 kB 0 B
frontend/dist/yaml 4.6 kB 0 B

compressed-size-action

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 20, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: frontend/src/lib/components/HogQLEditor/HogQLEditor.tsx
Line: 32

Comment:
**`--` inside string literals falsely suppresses the hint**

The regex `/--\s*\S+.*$/m` has no awareness of SQL string quoting, so an expression like `if(properties.status = '--disabled', 0, 1)` matches because `--disabled` appears in the string value. The `m` flag also means any `--` comment on *any* line (not just the last) will suppress the hint — though the PR description uses the word "contain", so that part seems intentional.

The string-literal false-positive means users writing expressions that compare against strings starting with `--` will never see the hint even when they have no alias. Given this is a UX hint (not a data-integrity guard), the impact is low, but it's worth noting.

```suggestion
    return /\bAS\s+[A-Za-z_][A-Za-z0-9_]*\s*$/i.test(expression) || /--\s*\S+[^\n]*$/.test(expression)
```

Removing the `m` flag keeps the same "contains a trailing `--` comment" semantics for single-line expressions while avoiding the multiline ambiguity; the string-literal case remains, but at least the scope is narrowed to the *last* line of the expression.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(insights): hint to alias SQL breakd..." | Re-trigger Greptile

Comment thread frontend/src/lib/components/HogQLEditor/HogQLEditor.tsx Outdated
Stripping quoted literals before testing for a trailing `AS name` alias or
`-- name` comment so an expression like `if(x = '--disabled', ...)` no longer
looks like it already has a label. Also narrows the `--` regex to the last
line of the expression instead of any line.

Generated-By: PostHog Code
Task-Id: 96d340a8-be92-4f3b-9e65-9fc7a74fe3b9
@rafaeelaudibert rafaeelaudibert merged commit e1664f8 into master Apr 21, 2026
165 checks passed
@rafaeelaudibert rafaeelaudibert deleted the posthog-code/sql-breakdown-label-hint branch April 21, 2026 17:58
inkeep Bot added a commit to PostHog/posthog.com that referenced this pull request Apr 21, 2026
Document the `AS column_name` and `-- column_name` aliasing technique
for SQL breakdown expressions, matching the in-product hint added in
PostHog/posthog#55405.
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented Apr 21, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-04-21 18:28 UTC Run
prod-us ✅ Deployed 2026-04-21 18:45 UTC Run
prod-eu ✅ Deployed 2026-04-21 18:47 UTC Run

thmsobrmlr pushed a commit that referenced this pull request Apr 21, 2026
## Problem

On an insight breakdown, if a user picks the SQL expression option and enters a non-trivial expression (e.g. `countIf(properties.$browser = 'Chrome')`), the raw expression is used verbatim as the column/series label. That's unreadable in charts and tables. Today, a user can work around this by aliasing the expression — either with `AS column_name` or with a trailing `-- column_name` comment — but there's no in-product hint that this is an option.

Context: [support ticket #335](https://posthog.slack.com/archives/C094MLV8SKX/p1775761471898039).

## Changes

- Added a `showBreakdownLabelHint` prop to `HogQLEditor`. When set, and the current buffered expression is longer than 20 characters and doesn't already end in an `AS <name>` alias or contain a `-- <name>` comment label, a small secondary-text tip is rendered directly under the editor hint:

  > Tip: add `AS column_name` or `-- column_name` to the end of your expression to use a readable label for this breakdown.

- Threaded the flag from `TaxonomicFilter` → `taxonomicFilterLogic` → the HogQL expression group's `componentProps` → `InlineHogQLEditor` → `HogQLEditor`, so the hint can be opted into per TaxonomicFilter usage.
- Set `hogQLExpressionShowBreakdownLabelHint` on the `TaxonomicFilter` rendered from `TaxonomicBreakdownPopover`, so the hint only appears in the insights breakdown flow (not in property filters, column selectors, etc., which also use the same editor).
- Combined the new prop with `hogQLGlobals` into a single `hogQLExpressionComponentProps` selector to stay within kea's `SelectorTuple` length limit on the `taxonomicGroups` selector.

## How did you test this code?

- `pnpm --filter=@posthog/frontend typescript:check` reports the same number of pre-existing errors before and after this change (no new TS errors introduced).
- `pnpm --filter=@posthog/frontend format` runs cleanly.
- No manual browser test performed in this agent environment — the dev server wasn't started, so the UI change itself has not been interactively verified. Reviewers should spot-check the breakdown popover with short (<= 20 char) expressions, long expressions, and long expressions that already use `AS` or `-- name`.

## Publish to changelog?

no

## 🤖 LLM context

Authored by PostHog Code based on a Slack request to surface the `AS column_name` / `-- column_name` workaround as an in-product hint on SQL breakdowns, gated on expression length > 20 characters.

---
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant