---
title: "ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1"
description: "ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine."
url: "https://swe.quest/articles/clickhouse-and-postgresql-a-match-made-in-data-heaven-part-1-7c7668b9b4913b70"
canonical: "https://clickhouse.com/blog/migrating-data-between-clickhouse-postgres"
source: "ClickHouse"
published: "2022-12-20"
difficulty: "medium"
kind: "How-to"
reading_minutes: 18
tags: ["analytics","postgres","query-engines","performance","sql"]
---

# ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-12-20, 18 min read, How-to. Original: [https://clickhouse.com/blog/migrating-data-between-clickhouse-postgres](https://clickhouse.com/blog/migrating-data-between-clickhouse-postgres)

## Summary

ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine. Simple WHERE clauses are pushed down to Postgres, while aggregation, joins, sorting and LIMIT run in ClickHouse. On the 28M-row UK house price dataset, a low-selectivity filter makes Postgres choose a parallel sequential scan over the index, taking about 28s, and querying through ClickHouse gives similar times because Postgres still does the scan. Queries using ClickHouse-specific functions such as toYear are not pushed down and can run much slower. Rewriting joins with conditional aggregates like medianIf, or copying the data into local MergeTree tables, is what delivers the large speedups.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL aggregation queries ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- PostgreSQL indexes and query plans ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- OLTP vs OLAP basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, PostgreSQL, Supabase, ClickHouse Cloud, MergeTree, UK price paid dataset

## Related posts

- [ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 2](https://swe.quest/articles/clickhouse-and-postgresql-a-match-made-in-data-heaven-part-2-67e202f8b29633ab.md): ClickHouse · 2023-01-26 · Medium · 8 min read · Analytics & OLAP, PostgreSQL, Data pipelines, SQL, Performance engineering
  ClickHouse dictionaries backed by a PostgreSQL source can replace joins against Postgres-resident mapping tables, keeping the data in memory and refreshing it via LIFETIME and an invalidate\_query.
- [Introducing pg\_clickhouse: A Postgres extension for querying ClickHouse](https://swe.quest/articles/introducing-pg-clickhouse-a-postgres-extension-for-querying-clickhouse-98de49fb9ae8bb75.md): ClickHouse · 2025-12-10 · Medium · 11 min read · PostgreSQL, Query engines, Analytics & OLAP, SQL
  pg\_clickhouse v0.1.0 is an Apache 2-licensed PostgreSQL foreign data wrapper, derived from clickhouse\_fdw, that runs analytics queries on ClickHouse from Postgres so existing queries can work unmodified by changing search\_path.
- [Longbridge Technology simplifies their architecture and achieves 10x performance boost with ClickHouse](https://swe.quest/articles/longbridge-technology-simplifies-their-architecture-and-achieves-10x-e3a982c02b6e4b33.md): ClickHouse · 2025-03-17 · Medium · 8 min read · Analytics & OLAP, Databases, PostgreSQL, Payments & fintech
  Longbridge, a Singapore online brokerage, replaced a fragmented market-data stack of PostgreSQL (historical), Redis (real-time) and DynamoDB (high-write) with ClickHouse after evaluating it against TimescaleDB and TDengine for write throughput, Decimal support, time functions and aggregations.
- [You can’t UPDATE what you can’t find: ClickHouse vs PostgreSQL](https://swe.quest/articles/you-can-t-update-what-you-can-t-find-clickhouse-vs-postgresql-6396a03839ca899c.md): ClickHouse · 2025-08-13 · Medium · 15 min read · Analytics & OLAP, PostgreSQL, Performance engineering, Databases, Storage engines
  ClickHouse 25.7's SQL-standard UPDATEs were benchmarked against PostgreSQL 17.5 on identical hardware using the 600M-row TPC-H lineitem table, with cold and hot runs.
- [HIFI’s migration from BigQuery to ClickHouse](https://swe.quest/articles/hifi-s-migration-from-bigquery-to-clickhouse-5318550bbb72f66e.md): ClickHouse · 2023-01-09 · Medium · 8 min read · Analytics & OLAP, SQL, Databases, JavaScript
  HIFI moved music royalty analytics from BigQuery to ClickHouse because BigQuery's per-query pricing discouraged exploratory use and slot reservations didn't fit a startup's shifting workloads.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
