Skip to content

PostHog

PostHog events, persons, sessions and HogQL as SQL, plus flags, experiments and insights

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/posthog/index.md to help me query PostHog with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Count product events over a day

Set the timestamp range to the day you want to analyze.

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT event, count(*) AS n
FROM posthog.main.events
WHERE timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00' AND timestamp < TIMESTAMPTZ '2026-11-02 00:00:00+00'
GROUP BY event
ORDER BY n DESC

Quick start

Choose where to run PostHog, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'posthog' AS posthog (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-posthog-worker'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

posthog credentials

Connection to one PostHog project: a personal API key (phx_...), the numeric project id, and the host (US Cloud by default; EU Cloud or a self-hosted URL via HOST).

Get these credentials →
secret.sql
CREATE SECRET posthog (
    TYPE posthog,
    personal_api_key '<PERSONAL_API_KEY>',  -- required, secret
    project_id       '<project_id>',
    host             '<host>',
    timeout          '<timeout>',
    page_size        '<page_size>',
    max_wait         '<max_wait>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT event, count(*) AS n
FROM posthog.main.events
WHERE timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00' AND timestamp < TIMESTAMPTZ '2026-11-02 00:00:00+00'
GROUP BY event
ORDER BY n DESC
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'posthog' AS posthog (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-posthog-worker'
);

Overview

PostHog product analytics as SQL: run HogQL through the Query API, read events, persons, sessions and groups with filters pushed into HogQL, and list feature flags, experiments, insights and other project resources. Works with US Cloud, EU Cloud and self-hosted PostHog.

Catalog

Everything posthog exposes once attached — read straight from the worker's released build.

posthog 2 schemas
main 5 tables · 3 functions

PostHog analytics data through the Query API: HogQL, events, persons, sessions, groups.

Schema examples (8)
Examples (8)

Event counts for one day (the timestamp range runs in HogQL)

SELECT event, count(*) AS n
FROM posthog.main.events
WHERE timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00' AND timestamp < TIMESTAMPTZ '2026-11-02 00:00:00+00'
GROUP BY event
ORDER BY n DESC;

Identified persons and their email property

SELECT id, properties->>'email' AS email, created_at
FROM posthog.main.persons
WHERE is_identified
ORDER BY created_at;

Persons with more than one distinct id

SELECT person_id, list(distinct_id ORDER BY distinct_id) AS ids
FROM posthog.main.person_distinct_ids
GROUP BY person_id
HAVING count(*) > 1;

Bounce rate and median duration per channel for November

SELECT channel_type, avg(is_bounce::INT) AS bounce_rate,
  median(duration_seconds) AS median_s
FROM posthog.main.sessions
WHERE start_timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
GROUP BY channel_type
ORDER BY bounce_rate DESC;
4 more examples

Companies by seat count

SELECT g.group_key, g.properties->>'name' AS name,
  (g.properties->>'seats')::INT AS seats
FROM posthog.main.groups g
JOIN posthog.metadata.group_types t USING (group_type_index)
WHERE t.group_type = 'company'
ORDER BY seats DESC;

Event counts computed in PostHog, with the date bound as a placeholder

SELECT event, n
FROM posthog.main.hogql('SELECT event, count() AS n FROM events WHERE timestamp >= {since} GROUP BY event', values := '{"since": "2026-11-01"}')
WHERE n > 1
ORDER BY n DESC;

Revenue from purchases by pro-plan users (property filter runs in HogQL)

SELECT count(*) AS purchases,
  sum((properties->>'amount')::DOUBLE) AS revenue
FROM posthog.main.events_where(event := 'purchase', properties := '{"plan": "pro"}');

A named ClickHouse tuple becomes a DuckDB STRUCT

SELECT posthog.main.clickhouse_type_to_duckdb('Tuple(label String, rank UInt8)') AS duckdb_type;
Tables
events 2 examples10 cols

PostHog events (HogQL events table), with WHERE pushed into HogQL.

Columns
uuidnot null VARCHAR
Event UUID, unique per event.
eventnot null VARCHAR
Event name, e.g. '$pageview' or 'signed_up'.
timestampnot null TIMESTAMP WITH TIME ZONE
When the event happened (UTC).
distinct_idnot null VARCHAR
Distinct id the event was captured with.
person_id VARCHAR
UUID of the person the distinct id resolves to.
session_id VARCHAR
Session id ($session_id property); NULL for events outside a session.
current_url VARCHAR
Page URL ($current_url property) for web events.
properties JSON
All event properties as a JSON object.
elements_chain VARCHAR
Autocapture element chain; empty for non-autocapture events.
created_at TIMESTAMP WITH TIME ZONE
When PostHog ingested the event (UTC).
ConstraintsPRIMARY KEY (uuid)
Examples (2)

Event counts for one day (the timestamp range runs in HogQL)

SELECT event, count(*) AS n
FROM posthog.main.events
WHERE timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00' AND timestamp < TIMESTAMPTZ '2026-11-02 00:00:00+00'
GROUP BY event
ORDER BY n DESC;

Pageviews per URL for one user

SELECT current_url, count(*) AS views
FROM posthog.main.events
WHERE event = '$pageview' AND distinct_id = 'user-1'
GROUP BY current_url
ORDER BY views DESC;
Link
groups 1 example4 cols

PostHog groups (HogQL groups table).

Columns
group_type_indexnot null INTEGER
Group type slot index, 0 to 4; names in metadata.group_types.
group_keynot null VARCHAR
The group's key, e.g. a company id.
created_at TIMESTAMP WITH TIME ZONE
When the group was first seen (UTC).
properties JSON
Group properties as a JSON object.
ConstraintsPRIMARY KEY (group_type_index, group_key)
Example

Companies by seat count

SELECT g.group_key, g.properties->>'name' AS name,
  (g.properties->>'seats')::INT AS seats
FROM posthog.main.groups g
JOIN posthog.metadata.group_types t USING (group_type_index)
WHERE t.group_type = 'company'
ORDER BY seats DESC;
Link
person_distinct_ids 1 example2 cols

Which person each distinct id resolves to (HogQL person_distinct_ids table).

Columns
distinct_idnot null VARCHAR
A distinct id seen in events.
person_idnot null VARCHAR
UUID of the person it currently resolves to.
ConstraintsPRIMARY KEY (distinct_id)
Example

Persons with more than one distinct id

SELECT person_id, list(distinct_id ORDER BY distinct_id) AS ids
FROM posthog.main.person_distinct_ids
GROUP BY person_id
HAVING count(*) > 1;
Link
persons 1 example4 cols

PostHog persons (HogQL persons table).

Columns
idnot null VARCHAR
Person UUID.
created_at TIMESTAMP WITH TIME ZONE
When the person was first seen (UTC).
is_identified BOOLEAN
True once the person was identified (posthog.identify).
properties JSON
Person properties as a JSON object.
ConstraintsPRIMARY KEY (id)
Example

Identified persons and their email property

SELECT id, properties->>'email' AS email, created_at
FROM posthog.main.persons
WHERE is_identified
ORDER BY created_at;
Link
sessions 1 example15 cols

PostHog sessions (HogQL sessions table).

Columns
session_idnot null VARCHAR
Session id (UUIDv7 text).
distinct_id VARCHAR
Distinct id of the session's first event.
start_timestamp TIMESTAMP WITH TIME ZONE
First event of the session (UTC).
end_timestamp TIMESTAMP WITH TIME ZONE
Last event of the session (UTC).
duration_seconds BIGINT
end_timestamp - start_timestamp in seconds.
entry_current_url VARCHAR
URL of the first pageview.
exit_current_url VARCHAR
URL of the last pageview.
entry_referring_domain VARCHAR
Referring domain of the first pageview.
entry_utm_source VARCHAR
utm_source of the first pageview.
entry_utm_medium VARCHAR
utm_medium of the first pageview.
entry_utm_campaign VARCHAR
utm_campaign of the first pageview.
channel_type VARCHAR
PostHog channel type, e.g. 'Direct', 'Organic Search'.
pageview_count BIGINT
Number of $pageview events (count).
autocapture_count BIGINT
Number of $autocapture events (count).
is_bounce BOOLEAN
True for a single-pageview session shorter than 10 seconds.
ConstraintsPRIMARY KEY (session_id)
Example

Bounce rate and median duration per channel for November

SELECT channel_type, avg(is_bounce::INT) AS bounce_rate,
  median(duration_seconds) AS median_s
FROM posthog.main.sessions
WHERE start_timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
GROUP BY channel_type
ORDER BY bounce_rate DESC;
Link
Scalar functions
clickhouse_type_to_duckdb (ch_type VARCHAR) 2 examples

DuckDB column type that hogql() produces for a ClickHouse type string from a HogQL response

Arguments
ch_type VARCHAR
ClickHouse type string from a HogQL response, e.g. 'Nullable(DateTime64(6, ''UTC''))'.
ReturnsVARCHAR
Examples (2)

A named ClickHouse tuple becomes a DuckDB STRUCT

SELECT posthog.main.clickhouse_type_to_duckdb('Tuple(label String, rank UInt8)') AS duckdb_type;
SELECT t, posthog.main.clickhouse_type_to_duckdb(t) AS duckdb_type
FROM (VALUES ('Nullable(String)'), ('DateTime64(6, ''UTC'')'), ('Array(UInt8)'), ('Decimal(18, 4)')) AS v(t)
ORDER BY t;
Link
Table functions
events_where (after := TIMESTAMP WITH TIME ZONE, before := TIMESTAMP WITH TIME ZONE, distinct_id := VARCHAR, event := VARCHAR, max_rows := BIGINT, newest_first := BOOLEAN, person_id := VARCHAR, properties := VARCHAR) 2 examples

Events filtered in HogQL by name, properties, ids and time, with an optional row cap

Named arguments
after := TIMESTAMP WITH TIME ZONE
Only events at or after this moment (inclusive). · default null
before := TIMESTAMP WITH TIME ZONE
Only events strictly before this moment (exclusive). · default null
distinct_id := VARCHAR
Distinct id to match exactly. · default null
event := VARCHAR
Event name to match exactly, e.g. '$pageview'. · default null
max_rows := BIGINT
Stop after this many events (sent to PostHog as LIMIT); NULL reads all. · default null
newest_first := BOOLEAN
Page from the newest event backwards (with max_rows: the latest N). · default false
person_id := VARCHAR
Person id to match exactly (the persons.id value). · default null
properties := VARCHAR
Property equalities as one JSON object mapping property key to value (for instance plan to pro); values are compared as text and a JSON null matches a missing property. · default null
Returns columns
uuid VARCHAR
Event UUID, unique per event.
event VARCHAR
Event name, e.g. '$pageview' or 'signed_up'.
timestamp TIMESTAMPTZ
When the event happened (UTC).
distinct_id VARCHAR
Distinct id the event was captured with.
person_id VARCHAR
UUID of the person the distinct id resolves to.
session_id VARCHAR
Session id ($session_id property); NULL for events outside a session.
current_url VARCHAR
Page URL ($current_url property) for web events.
properties JSON
All event properties as a JSON object.
elements_chain VARCHAR
Autocapture element chain; empty for non-autocapture events.
created_at TIMESTAMPTZ
When PostHog ingested the event (UTC).
Examples (2)

Revenue from purchases by pro-plan users (property filter runs in HogQL)

SELECT count(*) AS purchases,
  sum((properties->>'amount')::DOUBLE) AS revenue
FROM posthog.main.events_where(event := 'purchase', properties := '{"plan": "pro"}');

The 20 latest events of one user

SELECT timestamp, event, current_url
FROM posthog.main.events_where(distinct_id := 'user-1', max_rows := 20, newest_first := true)
ORDER BY timestamp DESC;
Link
hogql (query VARCHAR, max_rows := BIGINT, refresh := VARCHAR, values := VARCHAR) 2 examples

Run a HogQL query through PostHog's Query API and return its typed result

Positional arguments
query VARCHAR
A HogQL SELECT, e.g. 'SELECT event, count() AS n FROM events GROUP BY event'.
Named arguments
max_rows := BIGINT
Row cap sent as the outer LIMIT, 1 to 50000 (default 50000); 0 sends the query verbatim. · default 50000
refresh := VARCHAR
Query API refresh mode: 'blocking' (default), 'async' or 'force_async' (polled), 'force_blocking', 'force_cache' or 'lazy_async'. · default "blocking"
values := VARCHAR
JSON object of placeholder values referenced as {name} in the query, e.g. '{"ev": "$pageview"}' for WHERE event = {ev}. Use these instead of quoting constants. · default null
Returns columns
event VARCHAR
ClickHouse String: the event name.
n UBIGINT
ClickHouse UInt64: count() of events.
last_seen TIMESTAMPTZ
ClickHouse DateTime64(6, 'UTC'): latest event time.
Returns columns · depends on the arguments
event VARCHAR
ClickHouse String: the event name.
n UBIGINT
ClickHouse UInt64: count() of events.
last_seen TIMESTAMPTZ
ClickHouse DateTime64(6, 'UTC'): latest event time.
Examples (2)

Event counts computed in PostHog, with the date bound as a placeholder

SELECT event, n
FROM posthog.main.hogql('SELECT event, count() AS n FROM events WHERE timestamp >= {since} GROUP BY event', values := '{"since": "2026-11-01"}')
WHERE n > 1
ORDER BY n DESC;

Revenue per plan from purchase events

SELECT plan, sum(revenue) AS revenue
FROM posthog.main.hogql('SELECT properties.plan AS plan, toFloat(properties.amount) AS revenue FROM events WHERE event = {ev}', values := '{"ev": "purchase"}')
GROUP BY plan
ORDER BY revenue DESC;
Link
metadata 12 tables

PostHog project resources: definitions, flags, experiments, surveys, insights, dashboards.

Schema examples (12)
Examples (12)

Projects the key can read

SELECT id, name, timezone FROM posthog.metadata.projects ORDER BY id;

Group type names

SELECT group_type_index, group_type
FROM posthog.metadata.group_types
ORDER BY 1;

Verified events by 30-day volume

SELECT name, volume_30_day, last_seen_at
FROM posthog.metadata.event_definitions
WHERE verified
ORDER BY volume_30_day DESC NULLS LAST;

Numeric event properties

SELECT name, property_type
FROM posthog.metadata.property_definitions
WHERE definition_type = 'event' AND is_numerical
ORDER BY name;
8 more examples

Actions and the events their steps match

SELECT a.name, s.event, s.selector
FROM posthog.metadata.actions a,
     unnest(a.steps) AS u(s)
ORDER BY a.name;

Dynamic cohorts by size

SELECT name, count, last_calculation
FROM posthog.metadata.cohorts
WHERE NOT is_static AND NOT deleted
ORDER BY count DESC NULLS LAST;

Active flags and their rollout

SELECT key, rollout_percentage, is_multivariate
FROM posthog.metadata.feature_flags
WHERE active AND NOT deleted
ORDER BY key;

Running experiments

SELECT name, feature_flag_key, start_date
FROM posthog.metadata.experiments
WHERE start_date IS NOT NULL AND end_date IS NULL AND NOT archived
ORDER BY start_date;

Launched surveys and their size

SELECT name, type, question_count
FROM posthog.metadata.surveys
WHERE start_date IS NOT NULL
ORDER BY name;

Saved insights per query kind

SELECT query_kind, count(*) AS insights
FROM posthog.metadata.insights
WHERE saved AND NOT deleted
GROUP BY query_kind
ORDER BY insights DESC;

Pinned dashboards

SELECT id, name FROM posthog.metadata.dashboards WHERE pinned ORDER BY name;

Deploy annotations

SELECT date_marker, content
FROM posthog.metadata.annotations
WHERE creation_type = 'GIT'
ORDER BY date_marker;
Tables
actions 1 example8 cols

Saved actions and the match steps (event, URL, selector) that define them.

Columns
idnot null BIGINT
Numeric identifier of the action (ids, not quantities).
name VARCHAR
Action name.
description VARCHAR
Action description.
steps STRUCT of 7 fields[]
Match steps (any step matches): event, url, url_matching, selector, text, href, tag_name.
STRUCT[] 7 fields
  • eventVARCHAR
  • urlVARCHAR
  • url_matchingVARCHAR
  • selectorVARCHAR
  • textVARCHAR
  • hrefVARCHAR
  • tag_nameVARCHAR
tags VARCHAR[]
Tags on the action.
deleted BOOLEAN
True for a soft-deleted action.
created_at TIMESTAMP WITH TIME ZONE
When the action was created.
created_by VARCHAR
Email of the user who created the action.
ConstraintsPRIMARY KEY (id)
Example

Actions and the events their steps match

SELECT a.name, s.event, s.selector
FROM posthog.metadata.actions a,
     unnest(a.steps) AS u(s)
ORDER BY a.name;
Link
annotations 1 example10 cols

Chart annotations marking releases and incidents, from users or deploy integrations.

Columns
idnot null BIGINT
Numeric identifier of the annotation (ids, not quantities).
content VARCHAR
Annotation text.
date_marker TIMESTAMP WITH TIME ZONE
The moment the annotation marks on charts.
scope VARCHAR
Where it shows: dashboard_item, dashboard, project or organization.
creation_type VARCHAR
'USR' (user) or 'GIT' (from a deploy integration).
insight_id BIGINT
Insight the annotation is attached to, for scope dashboard_item (an id, not a quantity).
deleted BOOLEAN
True for a soft-deleted annotation.
created_at TIMESTAMP WITH TIME ZONE
When the annotation was created.
updated_at TIMESTAMP WITH TIME ZONE
When the annotation was last edited.
created_by VARCHAR
Email of the user who created the annotation.
ConstraintsPRIMARY KEY (id)
Example

Deploy annotations

SELECT date_marker, content
FROM posthog.metadata.annotations
WHERE creation_type = 'GIT'
ORDER BY date_marker;
Link
cohorts 1 example13 cols

Person cohorts with their size, calculation state and filter definition.

Columns
idnot null BIGINT
Numeric identifier of the cohort (ids, not quantities).
name VARCHAR
Cohort name.
description VARCHAR
Cohort description.
is_static BOOLEAN
True for a static (uploaded) cohort, false for a dynamic one.
count BIGINT
Persons in the cohort at the last calculation (count).
is_calculating BOOLEAN
True while PostHog recalculates the cohort.
last_calculation TIMESTAMP WITH TIME ZONE
When the cohort was last calculated.
errors_calculating BIGINT
Consecutive calculation errors (count).
deleted BOOLEAN
True for a soft-deleted cohort.
created_at TIMESTAMP WITH TIME ZONE
When the cohort was created.
created_by VARCHAR
Email of the user who created the cohort.
filters JSON
Cohort definition (property groups), JSON.
query JSON
HogQL/insight query defining the cohort, JSON (newer cohorts).
ConstraintsPRIMARY KEY (id)
Example

Dynamic cohorts by size

SELECT name, count, last_calculation
FROM posthog.metadata.cohorts
WHERE NOT is_static AND NOT deleted
ORDER BY count DESC NULLS LAST;
Link
dashboards 1 example9 cols

Analytics dashboards of the project, with pinned and sharing state.

Columns
idnot null BIGINT
Numeric identifier of the dashboard (ids, not quantities).
name VARCHAR
Dashboard name.
description VARCHAR
Dashboard description.
pinned BOOLEAN
True when pinned to the sidebar.
is_shared BOOLEAN
True when shared publicly.
deleted BOOLEAN
True for a soft-deleted dashboard.
tags VARCHAR[]
Tags on the dashboard.
created_at TIMESTAMP WITH TIME ZONE
When the dashboard was created.
created_by VARCHAR
Email of the user who created the dashboard.
ConstraintsPRIMARY KEY (id)
Example

Pinned dashboards

SELECT id, name FROM posthog.metadata.dashboards WHERE pinned ORDER BY name;
Link
event_definitions 1 example10 cols

Event catalog from data management: names, 30-day volume, last seen, verification.

Columns
idnot null VARCHAR
Definition UUID.
namenot null VARCHAR
Event name.
description VARCHAR
Description from the data management page.
tags VARCHAR[]
Tags on the definition.
verified BOOLEAN
True when a team member verified the event.
volume_30_day BIGINT
Events in the last 30 days (count; NULL when not computed).
query_usage_30_day BIGINT
Queries using the event in the last 30 days (count).
created_at TIMESTAMP WITH TIME ZONE
When the event was first defined.
last_seen_at TIMESTAMP WITH TIME ZONE
When the event was last ingested.
last_updated_at TIMESTAMP WITH TIME ZONE
When the definition was last edited.
ConstraintsPRIMARY KEY (id)
Example

Verified events by 30-day volume

SELECT name, volume_30_day, last_seen_at
FROM posthog.metadata.event_definitions
WHERE verified
ORDER BY volume_30_day DESC NULLS LAST;
Link
experiments 1 example12 cols

A/B experiments with their feature flag, launch and end dates, and metrics.

Columns
idnot null BIGINT
Numeric identifier of the experiment (ids, not quantities).
name VARCHAR
Experiment name.
description VARCHAR
Experiment description / hypothesis.
type VARCHAR
'product' or 'web'.
feature_flag_key VARCHAR
Key of the flag that splits traffic.
start_date TIMESTAMP WITH TIME ZONE
When the experiment was launched; NULL for a draft.
end_date TIMESTAMP WITH TIME ZONE
When the experiment was stopped; NULL while running.
archived BOOLEAN
True for an archived experiment.
created_at TIMESTAMP WITH TIME ZONE
When the experiment was created.
created_by VARCHAR
Email of the user who created the experiment.
parameters JSON
Experiment parameters (variants, minimum detectable effect), JSON.
metrics JSON
Primary metrics, JSON.
ConstraintsPRIMARY KEY (id)
Example

Running experiments

SELECT name, feature_flag_key, start_date
FROM posthog.metadata.experiments
WHERE start_date IS NOT NULL AND end_date IS NULL AND NOT archived
ORDER BY start_date;
Link
feature_flags 2 examples15 cols

Feature flags with variants, release conditions and rollout percentages (no payloads).

Columns
idnot null BIGINT
Numeric identifier of the flag (ids, not quantities).
keynot null VARCHAR
Flag key used in code, e.g. 'new-checkout'.
name VARCHAR
Flag description.
active BOOLEAN
True when the flag is enabled.
deleted BOOLEAN
True for a soft-deleted flag.
is_multivariate BOOLEAN
True when the flag has variants.
variants STRUCT of 3 fields[]
Variants: key, name and rollout_percentage (0-100).
STRUCT[] 3 fields
  • keyVARCHAR
  • nameVARCHAR
  • rollout_percentageDOUBLE
conditions STRUCT of 3 fields[]
Release conditions: rollout_percentage (0-100, NULL = 100), variant override, and the property filters as JSON text.
STRUCT[] 3 fields
  • rollout_percentageDOUBLE
  • variantVARCHAR
  • propertiesVARCHAR
rollout_percentage DOUBLE
Rollout of the first condition (0-100), when it has one.
ensure_experience_continuity BOOLEAN
True when flag values persist across identify.
has_payloads BOOLEAN
True when the flag carries payloads (the payloads are not exposed).
experiment_ids BIGINT[]
Numeric identifiers of the experiments that use the flag (ids, not quantities).
tags VARCHAR[]
Tags on the flag.
created_at TIMESTAMP WITH TIME ZONE
When the flag was created.
created_by VARCHAR
Email of the user who created the flag.
ConstraintsPRIMARY KEY (id)
Examples (2)

Active flags and their rollout

SELECT key, rollout_percentage, is_multivariate
FROM posthog.metadata.feature_flags
WHERE active AND NOT deleted
ORDER BY key;

Flags used by running experiments

SELECT f.key, e.name AS experiment, e.start_date
FROM posthog.metadata.feature_flags f
JOIN posthog.metadata.experiments e ON e.feature_flag_key = f.key
WHERE e.end_date IS NULL AND e.start_date IS NOT NULL
ORDER BY f.key;
Link
group_types 1 example4 cols

Group type slots of the project (company, team ...) with display names.

Columns
group_type_indexnot null INTEGER
Group type slot index, 0 to 4; matches main.groups.group_type_index.
group_typenot null VARCHAR
Group type key, e.g. 'company'.
name_singular VARCHAR
Display name, singular.
name_plural VARCHAR
Display name, plural.
ConstraintsPRIMARY KEY (group_type_index)
Example

Group type names

SELECT group_type_index, group_type
FROM posthog.metadata.group_types
ORDER BY 1;
Link
insights 2 examples15 cols

Saved insight definitions (query kind and query JSON) and the dashboards that show them.

Columns
idnot null BIGINT
Numeric identifier of the insight (ids, not quantities).
short_id VARCHAR
Short id used in insight URLs (/insights/<short_id>).
name VARCHAR
Insight name; NULL for unnamed insights.
derived_name VARCHAR
Name PostHog generated from the query.
description VARCHAR
Insight description.
query_kind VARCHAR
Kind of query, e.g. TrendsQuery, FunnelsQuery or HogQLQuery.
query JSON
Insight query definition, JSON.
dashboard_ids BIGINT[]
Numeric identifiers of the dashboards the insight is on (ids, not quantities).
favorited BOOLEAN
True when starred.
saved BOOLEAN
True for a saved insight.
deleted BOOLEAN
True for a soft-deleted insight.
tags VARCHAR[]
Tags on the insight.
created_at TIMESTAMP WITH TIME ZONE
When the insight was created.
created_by VARCHAR
Email of the user who created the insight.
last_modified_at TIMESTAMP WITH TIME ZONE
When the insight was last edited.
ConstraintsPRIMARY KEY (id)
Examples (2)

Saved insights per query kind

SELECT query_kind, count(*) AS insights
FROM posthog.metadata.insights
WHERE saved AND NOT deleted
GROUP BY query_kind
ORDER BY insights DESC;

Insights on each dashboard

SELECT d.name AS dashboard, count(*) AS insights
FROM posthog.metadata.insights i,
     unnest(i.dashboard_ids) AS u(dashboard_id)
JOIN posthog.metadata.dashboards d ON d.id = u.dashboard_id
GROUP BY d.name
ORDER BY d.name;
Link
projects 1 example8 cols

Projects (environments) the personal API key can read, with ids, names and time zones.

Columns
idnot null BIGINT
Project (environment) id; the PROJECT_ID secret field.
uuid VARCHAR
Project UUID.
name VARCHAR
Project name.
organization_id VARCHAR
UUID of the organization that owns the project.
timezone VARCHAR
Project time zone, e.g. 'UTC' or 'Europe/Berlin'.
is_demo BOOLEAN
True for a demo project.
ingested_event BOOLEAN
True once the project has received an event.
created_at TIMESTAMP WITH TIME ZONE
When the project was created.
ConstraintsPRIMARY KEY (id)
Example

Projects the key can read

SELECT id, name, timezone FROM posthog.metadata.projects ORDER BY id;
Link
property_definitions 1 example9 cols

Property catalog: keys of event, person, group and session properties with value types.

Columns
idnot null VARCHAR
Definition UUID.
namenot null VARCHAR
Property name, e.g. '$browser' or 'plan'.
definition_type VARCHAR
What the property belongs to: event, person, group or session.
group_type_index INTEGER
Group type slot index (0 to 4) for group properties; NULL otherwise.
property_type VARCHAR
Value type: String, Numeric, Boolean, DateTime or Duration.
is_numerical BOOLEAN
True when values are numbers.
description VARCHAR
Description from the data management page.
tags VARCHAR[]
Tags on the definition.
verified BOOLEAN
True when a team member verified the property.
ConstraintsPRIMARY KEY (id)
Example

Numeric event properties

SELECT name, property_type
FROM posthog.metadata.property_definitions
WHERE definition_type = 'event' AND is_numerical
ORDER BY name;
Link
surveys 1 example12 cols

Survey definitions with their questions, linked flag and launch dates.

Columns
idnot null VARCHAR
Survey UUID.
name VARCHAR
Survey name.
description VARCHAR
Survey description.
type VARCHAR
popover, widget, api or external_survey.
linked_flag_key VARCHAR
Flag that limits who sees the survey.
question_count INTEGER
Number of questions (count).
questions JSON
Questions (type, text, choices), JSON.
start_date TIMESTAMP WITH TIME ZONE
When the survey was launched; NULL for a draft.
end_date TIMESTAMP WITH TIME ZONE
When the survey was stopped.
archived BOOLEAN
True for an archived survey.
created_at TIMESTAMP WITH TIME ZONE
When the survey was created.
created_by VARCHAR
Email of the user who created the survey.
ConstraintsPRIMARY KEY (id)
Example

Launched surveys and their size

SELECT name, type, question_count
FROM posthog.metadata.surveys
WHERE start_date IS NOT NULL
ORDER BY name;
Link

Credentials

The secret type posthog declares, as reported by the worker itself.

posthog

How to get these credentials

Connection to one PostHog project: a personal API key (phx_...), the numeric project id, and the host (US Cloud by default; EU Cloud or a self-hosted URL via HOST).

secret.sql
CREATE SECRET posthog (
    TYPE posthog,
    personal_api_key '<PERSONAL_API_KEY>',  -- required, secret
    project_id       '<project_id>',
    host             '<host>',
    timeout          '<timeout>',
    page_size        '<page_size>',
    max_wait         '<max_wait>'
);
Key Type Required Description
personal_api_key secret VARCHAR Yes Personal API key (starts with phx_) with read access to Query and the project's resources. Not the project API key (phc_) used for capture.
project_id VARCHAR No Numeric project (environment) id from Project settings, e.g. '12345'. Needed by every table except metadata.projects.
host VARCHAR No PostHog app URL: 'https://us.posthog.com' (default), 'https://eu.posthog.com', or a self-hosted instance such as 'https://posthog.example.com'.
timeout DOUBLE No Per-request timeout in seconds (default 60).
page_size BIGINT No Rows per HogQL page for the typed tables, 1 to 50000 (default 10000).
max_wait DOUBLE No Seconds to keep polling an asynchronous query before giving up (default 300).

Needed by hogqlevents_where

Create the secret in the same session, after attaching posthog — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Identified persons and their email property

SELECT id, properties->>'email' AS email, created_at
FROM posthog.main.persons
WHERE is_identified
ORDER BY created_at

Uses persons

Persons with more than one distinct id

SELECT person_id, list(distinct_id ORDER BY distinct_id) AS ids
FROM posthog.main.person_distinct_ids
GROUP BY person_id
HAVING count(*) > 1

Uses person_distinct_ids

Bounce rate and median duration per channel for November

SELECT channel_type, avg(is_bounce::INT) AS bounce_rate,
  median(duration_seconds) AS median_s
FROM posthog.main.sessions
WHERE start_timestamp >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
GROUP BY channel_type
ORDER BY bounce_rate DESC

Uses sessions

Companies by seat count

SELECT g.group_key, g.properties->>'name' AS name,
  (g.properties->>'seats')::INT AS seats
FROM posthog.main.groups g
JOIN posthog.metadata.group_types t USING (group_type_index)
WHERE t.group_type = 'company'
ORDER BY seats DESC

Uses groupsgroup_types

Event counts computed in PostHog, with the date bound as a placeholder

SELECT event, n
FROM posthog.main.hogql('SELECT event, count() AS n FROM events WHERE timestamp >= {since} GROUP BY event', values := '{"since": "2026-11-01"}')
WHERE n > 1
ORDER BY n DESC

Uses hogqlevents

Revenue from purchases by pro-plan users (property filter runs in HogQL)

SELECT count(*) AS purchases,
  sum((properties->>'amount')::DOUBLE) AS revenue
FROM posthog.main.events_where(event := 'purchase', properties := '{"plan": "pro"}')

Uses events_where

19 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the posthog worker, how many events of each name were captured on 2026-11-01 (UTC)?
  • How many purchase events have the event property plan equal to 'pro', and what is their total amount?
  • List the keys of the active feature flags, with the rollout percentage of their first release condition.
  • Which sessions bounced? Give their session ids and entry URLs.
  • How many purchase events did each person make? Show the person's email property (NULL when unknown) and the count.
  • Which persons have more than one distinct id, and how many ids does each have?

PostHog is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.