Back to PostHog in Google Sheets
SheetXAI logo
PostHog logo
PostHog · Google Sheets Guide

Create PostHog Warehouse Saved Queries From a Google Sheet

2026-05-15
5 min read

The Scenario

A data team is migrating 20 analytics queries into PostHog's data warehouse. The HogQL for each query — session analysis, conversion funnels, cohort overlap — has been written and reviewed, and it's all sitting in a Google Sheet: query name in column A, HogQL in column B. The task is to register all 20 as PostHog warehouse saved queries so they're available to the rest of the team from the PostHog interface. Doing this through the UI means clicking "New saved query," pasting the name, pasting the HogQL, saving — 20 times. The last data migration someone did this way took a morning and produced three typos in query names that had to be hunted down later.

The bad version:

  • Open PostHog's data warehouse section, click "New saved query," paste the query name from row 1, paste the HogQL from the same row, save — and repeat for the remaining 19 rows
  • Reach query 9 and realize the HogQL for session analysis includes a single-quote in a string literal — pasting it into the UI text field works fine, but you're not sure if the API will handle it the same way, so you spend 15 minutes testing before continuing
  • Finish all 20, check the saved query list in PostHog, discover that query 14 has a truncated name because you accidentally hit enter mid-paste and PostHog saved what was on the first line

Twenty queries, one paste-and-click per query, with a truncation risk hiding in every complex HogQL string.

The Easy Way: One Prompt in SheetXAI

SheetXAI is an AI agent inside your Google Sheet. It reads your query definition table and calls PostHog's warehouse saved query create endpoint for each row — writing the returned query IDs back into column C.

For each row in the 'Saved Queries' sheet (query name in column A, HogQL in column B), create a PostHog warehouse saved query and write the returned query ID into column C.

What You Get

  • PostHog creates one saved query per row using the exact name and HogQL from the sheet
  • Column C receives the returned query ID for each row — your record linking the definition to the live PostHog query
  • Any row that fails (syntax error in HogQL, duplicate name) gets an error note in column C

What If the Data Is Not Quite Ready

Some HogQL contains multi-line formatting that needs cleanup

Before creating PostHog warehouse saved queries, normalize column B: collapse any multi-line HogQL into single-line strings by replacing newlines with a space. Then create a saved query for each row and write returned IDs into column C.

You want to skip rows where the HogQL column is blank

For each row in the 'Warehouse Queries' tab where column B (HogQL) is not empty, create a PostHog warehouse saved query using name from column A and HogQL from column B. Write IDs into column C. Write "Skipped - blank HogQL" in column C for rows with an empty column B.

Queries are split across two sheets

Combine all rows from the 'Funnel Queries' tab and the 'Retention Queries' tab (each with name in column A, HogQL in column B). Create PostHog warehouse saved queries for all combined rows. Write returned IDs back into column C of the respective source tab.

Create all 20, validate creation, and build a reference index

Create PostHog warehouse saved queries for all rows in the 'Warehouse Queries' tab (name in column A, HogQL in column B). Write returned query IDs into column C. Then create a 'Query Index' sheet with three columns: query name, ID, and a PostHog URL constructed as https://us.posthog.com/data-warehouse/[query-id]. Sort the index alphabetically by query name.

One prompt creates all queries and produces a linked reference index.

Try It

Get the 7-day free trial of SheetXAI and open the spreadsheet where your HogQL definitions are staged, ask it to register all of them as PostHog warehouse saved queries, and hand the ID list to the team before the end of the sprint. Also see: Create PostHog Batch Export Configurations From a Google Sheet and the PostHog hub.

Stop memorizing formulas.
Tell your spreadsheet what to do.

Join 4,000+ professionals saving hours every week with SheetXAI.

Learn more