Skip to content

PostHog Product Analytics in VS Code

PostHog is a product analytics platform that stores event, person, and session data in ClickHouse. Key characteristics include:

  • HogQL query language: PostHog’s ClickHouse-flavored SQL dialect, queried through PostHog’s own query API
  • Virtual tables: Every project exposes events, persons, sessions, and groups, plus any data warehouse tables and views you’ve connected in PostHog
  • Cloud or self-hosted: Connect to PostHog Cloud (US or EU) or your own self-hosted instance
  • Read-only: HogQL is SELECT-only, so there is no data editing

DBCode connects to PostHog’s query API using a personal API key, so you can explore your product analytics data with SQL without leaving Visual Studio Code.

To connect to PostHog in DBCode:

  1. Open the DBCode Extension: Launch Visual Studio Code and open the DBCode extension.
  2. Add a New Connection: Click on the “Add Connection” icon.
  3. Complete connection form: Select PostHog as the database type and enter:
    • Region: US Cloud, EU Cloud, or Self-hosted (enter your instance URL)
    • Personal API Key: create one in PostHog under Settings > Personal API Keys with the query:read, project:read, and organization:read scopes, then paste it here
  4. Connect: Click save to establish your connection.
  5. Start Exploring: Projects appear as databases; pick one and start browsing tables.

The organization:read scope lets DBCode list every project across every organization the key can reach, with the organization name shown next to each project in the picker. A key without that scope still works, but only sees its own project.

For detailed instructions on connecting to databases, refer to the Connect article.

DBCode enhances your PostHog experience with:

  • Schema browsing: Browse events, persons, sessions, groups, and any data warehouse tables or views in the object tree
  • SQL query editor: Write and run HogQL with syntax highlighting, including properties.foo property access
  • Compiled SQL: See the ClickHouse SQL PostHog compiles your HogQL into, including the joins HogQL adds behind the scenes
  • Data exploration: Preview and export query results
  • Query cancellation: Long-running queries can be cancelled

HogQL is SELECT-only, so PostHog connections are read-only: there is no insert, update, delete, or schema modification.

PostHog support is in Preview:

  • Row limits: Results cap at 50,000 rows; un-LIMITed queries are capped by PostHog at 100 rows, and the grid shows a truncation indicator when that happens.
  • No OFFSET: PostHog rejects OFFSET in query API requests, so scrolling very deep into a result set in the data grid is limited.
  • Boolean display: PostHog’s API types boolean-semantic values as integers, so they display as 1/0 rather than true/false in the grid.
  • Rate limits: PostHog’s query API is limited to 2,400 queries/hour per organization (120/hour on some older accounts).

By using PostHog with DBCode, you can explore your product analytics data with SQL directly within Visual Studio Code.

For more information about PostHog, visit posthog.com.