Introducing HogQL: Direct SQL access for PostHog
Contents
Today, we're releasing a major new feature as a public beta: the ability to directly query your PostHog data using SQL. We call this HogQL because... hedgehogs love SQL, probably?
You can use HogQL expressions to enhance insights, filter event lists, and write full queries to analyze data in any way you want.
PostHog's existing insights are already incredibly powerful. HogQL turns insights Super Saiyan.
HogQL is free for all users of PostHog Cloud while in public beta โ all we ask is that you share your feedback with us.
What is HogQL?
It's a translation layer over ClickHouse SQL. It's intuitive for anyone familiar with SQL, but it offers a few advantages and customizations.
Features unique to HogQL include simplified access to event and person properties, like the autocapture element chain. It also automatically adds joins when you query fields with data on a different table, such as events.person.properties.$browser.
You can also use subqueries, joins, table expressions, arrays, lambdas, and a whole host of other neat SQL features, including aggregations.
See our HogQL documentation for a full list of supported ClickHouse SQL functions.
Not a PostHog user? Get started for free โ all users get 1 million events and 5k recordings free every month, no card required.
What can you do with HogQL?
Too much to list in one blog post, but here are a few examples:
HogQL breakdowns = multiple properties
Want to break down signups by both pricing tier and overall usage? No problem. HogQL does that. With HogQL, you can add as many breakdown properties as you like. Go nuts.
๐ Related tutorial: Using HogQL for advanced breakdowns
HogQL filters
Oh, look. You can use HogQL in filters too. Useful for filtering by multiple properties!
๐ Related tutorial Using HogQL for advanced time and date filters
HogQL aggregations
And you can use HogQL to aggregate results in a funnel, too. Is there anything HogQL can't do? Probably, yes, but we'll enjoy finding out for sure.
๐ Related tutorial The power of HogQLโs sum() aggregation
Custom SQL insights
Of course, the most powerful way to leverage HogQL within PostHog is via the new SQL insight type. This gives you direct SQL access to your data in PostHog, so you can create custom table insights that answer complex questions.
For example, while you can use a retention insight to discover which features keep users coming back for more, you could build an SQL insight to find which users keep coming back, and identify outliers.
We're confident SQL insights will unlock deep analysis into how users use your products, and we can't wait to hear your feedback and see how you use SQL access in PostHog.
To get a flavor, here's an example query summarizing survey data. Its purpose? Determining which countries prefer pineapple on a pizza. This is serious analysis:1