re2
ClickHouse-compatible regex functions using RE2
Repository
ClickHouse/pg_re2
https://github.com/ClickHouse/pg_re2
Source
re2-0.1.1.tar.gz
re2-0.1.1.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
re2 | 0.1.1 | UTIL | PostgreSQL | C++ |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4235 | re2 | No | Yes | No | Yes | Yes | Yes | - |
release 0.1.1; SQL v0.1
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.1 | 1817161514 | re2 | - |
| RPM | PIGSTY | 0.1.1 | 1817161514 | re2_$v | - |
| DEB | PIGSTY | 0.1.1 | 1817161514 | postgresql-$v-re2 | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.1.1 el8.x86_64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.1.1 el8.x86_64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.1.1 el8.x86_64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el8.aarch64 | PIGSTY 0.1.1 el8.aarch64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.1.1 el8.aarch64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.1.1 el8.aarch64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el9.x86_64 | PIGSTY 0.1.1 el9.x86_64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.1.1 el9.x86_64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.1.1 el9.x86_64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el9.aarch64 | PIGSTY 0.1.1 el9.aarch64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.1.1 el9.aarch64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.1.1 el9.aarch64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.x86_64 | PIGSTY 0.1.1 el10.x86_64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.1.1 el10.x86_64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.1.1 el10.x86_64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY 0.1.1 el10.aarch64.pg18 : re2_18 re2_18-0.1.1-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.1.1 el10.aarch64.pg17 : re2_17 re2_17-0.1.1-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.1.1 el10.aarch64.pg16 : re2_16 re2_16-0.1.1-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 0.1.1 d12.x86_64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.1.1 d12.x86_64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.1.1 d12.x86_64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~bookworm_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d12.aarch64 | PIGSTY 0.1.1 d12.aarch64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.1.1 d12.aarch64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.1.1 d12.aarch64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~bookworm_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.x86_64 | PIGSTY 0.1.1 d13.x86_64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.1.1 d13.x86_64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.1.1 d13.x86_64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~trixie_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY 0.1.1 d13.aarch64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.1.1 d13.aarch64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.1.1 d13.aarch64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~trixie_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 0.1.1 u22.x86_64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.1.1 u22.x86_64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.1.1 u22.x86_64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~jammy_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.aarch64 | PIGSTY 0.1.1 u22.aarch64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.1.1 u22.aarch64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.1.1 u22.aarch64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~jammy_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.x86_64 | PIGSTY 0.1.1 u24.x86_64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~noble_amd64.deb
| PIGSTY 0.1.1 u24.x86_64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~noble_amd64.deb
| PIGSTY 0.1.1 u24.x86_64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~noble_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.aarch64 | PIGSTY 0.1.1 u24.aarch64.pg18 : postgresql-18-re2 postgresql-18-re2_0.1.1-1PIGSTY~noble_arm64.deb
| PIGSTY 0.1.1 u24.aarch64.pg17 : postgresql-17-re2 postgresql-17-re2_0.1.1-1PIGSTY~noble_arm64.deb
| PIGSTY 0.1.1 u24.aarch64.pg16 : postgresql-16-re2 postgresql-16-re2_0.1.1-1PIGSTY~noble_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
Build
You can build the RPM / DEB packages for re2 using pig build:
pig build pkg re2 # build RPM / DEB packages
Install
You can install re2 directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install re2; # Install for current active PG version
pig ext install -y re2 -v 18 # PG 18
pig ext install -y re2 -v 17 # PG 17
pig ext install -y re2 -v 16 # PG 16
pig ext install -y re2 -v 15 # PG 15
pig ext install -y re2 -v 14 # PG 14
dnf install -y re2_18 # PG 18
dnf install -y re2_17 # PG 17
dnf install -y re2_16 # PG 16
dnf install -y re2_15 # PG 15
dnf install -y re2_14 # PG 14
apt install -y postgresql-18-re2 # PG 18
apt install -y postgresql-17-re2 # PG 17
apt install -y postgresql-16-re2 # PG 16
apt install -y postgresql-15-re2 # PG 15
apt install -y postgresql-14-re2 # PG 14
Create Extension:
CREATE EXTENSION re2;
Usage
Sources: official README, official reference doc, v0.1.1 release
re2 provides ClickHouse-compatible regular expression functions backed by Google’s RE2 engine. It exposes both text and bytea overloads, so binary data with \\0 bytes can be searched too.
CREATE EXTENSION re2;
SELECT re2match('hello world', 'h.*o');
SELECT re2extract('Order #123', '(\\d+)');
SELECT re2countmatches('a1 b2 c3', '\\d');
Core Functions
re2match(haystack, pattern) -> booleanre2extract(haystack, pattern) -> text|byteare2extractall(haystack, pattern) -> text[]|bytea[]re2regexpextract(haystack, pattern, index default 1) -> text|byteare2extractgroups(haystack, pattern) -> text[]|bytea[]re2replaceregexpone(haystack, pattern, replacement) -> text|byteare2replaceregexpall(haystack, pattern, replacement) -> text|byteare2countmatches(...)andre2countmatchescaseinsensitive(...)
Multi-Pattern Matching
The re2multimatch* family accepts either multiple pattern arguments or a VARIADIC array:
SELECT re2multimatchany('error: timeout', 'timeout', 'denied');
SELECT re2multimatchanyindex('error: timeout', VARIADIC ARRAY['timeout', 'denied']);
SELECT re2multimatchallindices('error: timeout', 'error', 'timeout', 'panic');
Matching Semantics
- To match ClickHouse behavior,
.matches line breaks by default. - Prefix the pattern with
(?-s)if you want.not to cross line breaks. - Replacement strings support
\\0through\\9backreferences.
Caveats
- Upstream requires the system
re2library at build/install time. - The
v0.1.1release is binary-only: it adds PostgreSQL 13+ support and documentsVARIADICuse for multi-pattern functions, but existingv0.1SQL installations do not needALTER EXTENSION UPDATE.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.