posthog icon indicating copy to clipboard operation
posthog copied to clipboard

feat(BI): postgres hogql

Open mariusandra opened this issue 1 month ago • 7 comments

Problem

No problems, only solutions

Changes

  • Refactor the HogQL printer, (mostly) split out the HogQL and ClickHouse parts
  • Adds a WIP postgres connector to HogQL
  • Adds YOLO support for connecting to the app's postgres when adding --pg to the beginning or end of the query
  • All of these work:
--pg

-- SELECT version();
-- SELECT regexp_replace('bananas are amazing', 'a(.)', '[$1]',  'g')
-- SELECT jsonb_pretty(
--   jsonb_build_object(
--     'name', 'ChatGPT',
--     'skills', jsonb_build_array('SQL', 'Postgres', 'Dad jokes'),
--     'nested', jsonb_build_object('x', 1, 'y', 2)
--   )  
-- );

select u.email, t.name, version() 
from postgres.posthog_user u
left join posthog_team t on t.id = u.current_team_id

How did you test this code?

Clicked on things

mariusandra avatar Dec 09 '25 17:12 mariusandra

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data 1 Info
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Software Supply Chain Finding Software Supply Chain Findings -
Total 1 Info

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

wiz-7ad640923b[bot] avatar Dec 09 '25 19:12 wiz-7ad640923b[bot]

Size Change: +1.01 kB (+0.03%)

Total Size: 3.7 MB

Filename Size Change
frontend/dist/toolbar.js 3.7 MB +1.01 kB (+0.03%)

compressed-size-action

github-actions[bot] avatar Dec 09 '25 19:12 github-actions[bot]

Visual regression: Storybook UI snapshots updated

Changes: 24 snapshots (24 modified, 0 added, 0 deleted)

What this means:

  • Snapshots have been automatically updated to match current rendering
  • Next CI run will switch to CHECK mode to verify stability
  • If snapshots change again, CHECK mode will fail (indicates flapping)

Next steps:

  • Review the changes to ensure they're intentional
  • Approve if changes match your expectations
  • If unexpected, investigate component rendering

Review snapshot changes →

posthog-bot avatar Dec 10 '25 12:12 posthog-bot

Migration SQL Changes

Hey đź‘‹, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:

products/data_warehouse/backend/migrations/0012_add_is_direct_query.py

BEGIN;
--
-- Add field is_direct_query to externaldatasource
--
ALTER TABLE "posthog_externaldatasource" ADD COLUMN "is_direct_query" boolean DEFAULT false NOT NULL;
ALTER TABLE "posthog_externaldatasource" ALTER COLUMN "is_direct_query" DROP DEFAULT;
COMMIT;

Last updated: 2025-12-12 01:38 UTC (8f7ac84)

github-actions[bot] avatar Dec 10 '25 13:12 github-actions[bot]

🔍 Migration Risk Analysis

We've analyzed your migrations for potential risks.

Summary: 1 Safe | 0 Needs Review | 0 Blocked

âś… Safe

Brief or no lock, backwards compatible

data_warehouse.0012_add_is_direct_query
  └─ #1 ✅ AddField
     Adding NOT NULL field with constant default (safe in PG11+)
     model: externaldatasource, field: is_direct_query

Last updated: 2025-12-12 01:38 UTC (8f7ac84)

github-actions[bot] avatar Dec 10 '25 13:12 github-actions[bot]

⏭️ Skipped snapshot commit because branch advanced to 66ba877 while workflow was testing 52fea87.

The new commit will trigger its own snapshot update workflow.

If you expected this workflow to succeed: This can happen due to concurrent commits. To get a fresh workflow run, either:

  • Merge master into your branch, or
  • Push an empty commit: git commit --allow-empty -m 'trigger CI' && git push

posthog-bot avatar Dec 10 '25 13:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 3 snapshots (3 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 10 '25 14:12 posthog-bot

⏭️ Skipped snapshot commit because branch advanced to 6688a64 while workflow was testing 6f54455.

The new commit will trigger its own snapshot update workflow.

If you expected this workflow to succeed: This can happen due to concurrent commits. To get a fresh workflow run, either:

  • Merge master into your branch, or
  • Push an empty commit: git commit --allow-empty -m 'trigger CI' && git push

posthog-bot avatar Dec 10 '25 15:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 2 snapshots (2 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 10 '25 15:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 1 snapshots (1 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 12 '25 00:12 posthog-bot