Creating views

Last updated:

|Edit this page

In the PostHog data warehouse, you can save your most used queries as views and reference them in subsequent queries.

Creating a view

Query views are created directly inside SQL insights. If the query has valid view characteristics, the "Save as view" button is enabled. When clicked, you are prompted to give the view a name which can then be referenced in other queries.

For a query to be a valid view, all fields being accessed must be aliased (with the SQL as keyword). The alias names are how you access the fields on the view.

Note: Currently, nested views are not supported. You cannot create a view based on other views, only base PostHog models.

valid view

Extending PostHog models with views

Views are a powerful tool for extending existing PostHog models for easier data access. For example, if you wanted to associate your Stripe customer data with product usage data of your users, you would normally need to manually set up a join. With views, you can attach views to PostHog models so that you can directly access those fields on the PostHog table.

To link a view to a PostHog table, go to the data warehouse section, select the PostHog tab, and click "Link table to view." Select your tables, keys to join, and press save. Once done, when you query that PostHog table, you can access the data from your view.

view link


Was this page useful?

Next article

Under the hood

Custom sources With custom sources, each table in the warehouse is backed by one or more files in your object storage system (i.e. S3, GCS). We never "ingest" your data into our systems. Instead, on every query, we'll read directly from your object storage system. This means you can store and query as much data as you want. This also means data freshness is determined by you. Data is as up-to-date as you set it up to be. Connectors Connectors use a combination of Temporal and the open source…

Read next article