posthog/posthog-foss

writing-clickhouse-queries

Guide for writing performant ClickHouse queries in PostHog product code.

First seen Jun 24, 2026

Installation

$ npx skills add posthog/posthog-foss --skill writing-clickhouse-queries

Summary

  • Guide for writing performant ClickHouse queries in PostHog product code.
  • Use when writing HogQL query runners, designing a ClickHouse table for a new product, adding materialized columns or skip indexes, or choosing a row ID format.
  • For optimizing an existing query that is already too slow, use `/optimizing-clickhouse-and-hogql-queries` instead.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from posthog/posthog-foss · top by installs.

npx skills add posthog/posthog-foss

Browse all from posthog/posthog-foss

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 516
License LICENSE
Default branch master
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,298 B
  • docs SUMMARY.md 381 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 5 installs

SKILL.md

Writing ClickHouse queries for new products

If you're optimizing an existing query rather than writing a new one, this is the wrong skill. Use [/optimizing-clickhouse-and-hogql-queries](../optimizing-clickhouse-and-hogql-queries/SKILL.md) instead. That skill covers layer triage, smell scanning (FROM ... FINAL, JSONExtract over properties, missing skip indexes, self-joins, CTE blow-up), measurement on the Test Cluster, and applying the fix at the right layer.

Read [docs/published/handbook/engineering/databases/clickhouse-queries-new-products.md](../../../docs/published/handbook/engineering/databases/clickhouse-queries-new-products.md) for the authoritative guide on writing new queries.

Then pull in whichever related docs the task touches:

  • [hogql-python.md](../../../docs/published/handbook/engineering/databases/hogql-python.md) for HogQL in Python
  • [materialized-columns.md](../../../docs/published/handbook/engineering/databases/materialized-columns.md)
  • [query-performance-optimization.md](../../../docs/published/handbook/engineering/databases/query-performance-optimization.md)

When to use

  • Writing or reviewing a QueryRunner subclass in posthog/hogql_queries/ or products/*/backend/
  • Adding a new ClickHouse table or ALTER for a product (posthog/clickhouse/migrations/)
  • Choosing a row ID format for a new table
  • Adding or removing materialized columns, skip indexes, or projections

For investigating an existing slow query, debugging a system.query_log row, or reviewing a proposed HogQL printer change for performance, use [/optimizing-clickhouse-and-hogql-queries](../optimizing-clickhouse-and-hogql-queries/SKILL.md).

Not the right skill for: customer-facing ad-hoc HogQL via Max / posthog:execute-sql, use query-examples for that. For migration mechanics (node roles, engines, replication), use clickhouse-migrations.