AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

tools-and-features-hogql

HogQL queries for PostHog analytics

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--tools-and-features-hogql at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 9

references/variables.md

SQL variables - Docs

SQL variables enable you to dynamically set values in your queries.

Creating SQL variables

To create a variable, go to the SQL editor and click the Variables button in the top right toolbar. Start typing in your variable name, if it doesn't exist already, select New variable and create it. The variable is now available in any of your project's queries.

For example, you can create a List type variable with the code name event_names and add events like $pageview and $autocapture as values.

SQL variables dropdown in the toolbarSQL variables dropdown in the toolbar

Using variables in SQL queries

Once created, variables can be used in queries with the {variables.<variable-name>} syntax like this:

SQL

Run in PostHog

PostHog AI

select *
from events
where event = {variables.event_names}

You can set the value for the variable in the Variables dropdown. For example, below we set the "event names" variable to $autocapture on a dashboard. This means every instance of {variables.event_names} in the queries on the dashboard is replaced with $autocapture.

Using a variable in a SQL queryUsing a variable in a SQL query

Dashboard date range filter variables

Beyond the SQL variables you set up, you can access the dashboard's date range filters through the filters.dateRange.from and filters.dateRange.to variables like this:

SQL

Run in PostHog

PostHog AI

select *
from events
where event = {variables.event_names}
and timestamp >= {filters.dateRange.from} and timestamp < {filters.dateRange.to}

Using dashboard filter variables in a SQL queryUsing dashboard filter variables in a SQL query

Community questions

Ask a question

Was this page useful?

HelpfulCould be better