---
title: "Introducing pg_re2, fast, RE2-powered regular expressions in Postgres"
description: "pg_re2 is a Postgres extension that replaces backtracking POSIX regex with Google's automata-based RE2 engine, beating Postgres builtins by 1.8x to 8.6x on table scans and 1.1x to 1.8x on index scans."
url: "https://swe.quest/articles/introducing-pg-re2-fast-re2-powered-regular-expressions-in-postgres-0fcf212bf9544079"
canonical: "https://clickhouse.com/blog/introducing-pg_re2-regex-in-postgres"
source: "ClickHouse"
published: "2026-07-08"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 8
tags: ["postgres","performance","query-engines","analytics"]
---

# Introducing pg\_re2, fast, RE2-powered regular expressions in Postgres

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-07-08, 8 min read, Announcement. Original: [https://clickhouse.com/blog/introducing-pg\_re2-regex-in-postgres](https://clickhouse.com/blog/introducing-pg_re2-regex-in-postgres)

## Summary

pg\_re2 is a Postgres extension that replaces backtracking POSIX regex with Google's automata-based RE2 engine, beating Postgres builtins by 1.8x to 8.6x on table scans and 1.1x to 1.8x on index scans. The extension adds an \`@~\` operator with btree and GIN (\`gin\_re2\_ops\`) index support, which can use trigram indexes for patterns like \`error\_code=42\[0-9\]\` where \`pg\_trgm\` falls back to a full scan. It also fixes semantic mismatches with pg\_clickhouse pushdown: \`\\b\` means backspace in Postgres but word boundary in ClickHouse, and flags, backreferences and lookarounds differ too. Using pg\_re2 functions such as \`re2match()\` gives the same results whether a query runs locally or is pushed down to ClickHouse.

Written by swe.quest, not by the author.

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

## Topics

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

## Prerequisites

- Postgres extensions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- regular expressions
- foreign data wrappers

## Keywords

pg\_re2, RE2, ClickHouse, pg\_clickhouse, pg\_trgm, GIN index, PostgreSQL 18

## Related posts

- [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.
- [ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1](https://swe.quest/articles/clickhouse-and-postgresql-a-match-made-in-data-heaven-part-1-7c7668b9b4913b70.md): ClickHouse · 2022-12-20 · Medium · 18 min read · Analytics & OLAP, PostgreSQL, Query engines, Performance engineering, SQL
  ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine.
- [What's New in pg\_clickhouse v0.3.2: Postgres 19, TLS, Regex, and Memory](https://swe.quest/articles/what-s-new-in-pg-clickhouse-v0-3-2-postgres-19-tls-regex-and-memory-db831637f7730c4c.md): ClickHouse · 2026-06-23 · Medium · 2 min read · PostgreSQL, Analytics & OLAP, Databases
  pg\_clickhouse v0.3.2, the Postgres extension for querying ClickHouse, adds support for PostgreSQL 19 Beta1 and needs no restart or ALTER EXTENSION UPDATE.
- [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.
- [pg\_search is Available on Neon](https://swe.quest/articles/pg-search-is-available-on-neon-98d919ff82afb749.md): Neon · 2025-03-18 · Medium · 8 min read · PostgreSQL, Search, Performance engineering
  ParadeDB's pg\_search extension, now available on Neon in AWS regions, adds a Tantivy-powered BM25 inverted index to Postgres, bringing relevance ranking, fuzzy matching, faceting, highlighting and JSON-aware search that native tsvector/GIN full-text search lacks.

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)
