feat(insights): hint to alias SQL breakdown expressions#55405
Merged
rafaeelaudibert merged 2 commits intomasterfrom Apr 21, 2026
Merged
feat(insights): hint to alias SQL breakdown expressions#55405rafaeelaudibert merged 2 commits intomasterfrom
rafaeelaudibert merged 2 commits intomasterfrom
Conversation
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
Contributor
|
Size Change: +2.44 kB (0%) Total Size: 129 MB ℹ️ View Unchanged
|
Contributor
Prompt To Fix All With AIThis 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 |
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
approved these changes
Apr 21, 2026
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.
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)*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withAS column_nameor with a trailing-- column_namecomment — but there's no in-product hint that this is an option.Context: support ticket #335.
Changes
Added a
showBreakdownLabelHintprop toHogQLEditor. When set, and the current buffered expression is longer than 20 characters and doesn't already end in anAS <name>alias or contain a-- <name>comment label, a small secondary-text tip is rendered directly under the editor hint:Threaded the flag from
TaxonomicFilter→taxonomicFilterLogic→ the HogQL expression group'scomponentProps→InlineHogQLEditor→HogQLEditor, so the hint can be opted into per TaxonomicFilter usage.Set
hogQLExpressionShowBreakdownLabelHinton theTaxonomicFilterrendered fromTaxonomicBreakdownPopover, 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
hogQLGlobalsinto a singlehogQLExpressionComponentPropsselector to stay within kea'sSelectorTuplelength limit on thetaxonomicGroupsselector.How did you test this code?
pnpm --filter=@posthog/frontend typescript:checkreports the same number of pre-existing errors before and after this change (no new TS errors introduced).pnpm --filter=@posthog/frontend formatruns cleanly.ASor-- name.Publish to changelog?
no
🤖 LLM context
Authored by PostHog Code based on a Slack request to surface the
AS column_name/-- column_nameworkaround as an in-product hint on SQL breakdowns, gated on expression length > 20 characters.Created with PostHog Code