pg_query_rewrite
pg_query_rewrite : Rewrite SQL statements with a PostgreSQL ProcessUtility hook
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5030 | pg_query_rewrite
|
pg_query_rewrite
|
0.0.5 |
ADMIN
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd--
|
No
|
Yes
|
Yes
|
Yes
|
no
|
no
|
Requires shared_preload_libraries=pg_query_rewrite.
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.0.5 |
18
17
16
15
14
|
pg_query_rewrite |
- |
| RPM | PIGSTY
|
0.0.5 |
18
17
16
15
14
|
pg_query_rewrite_$v |
- |
| DEB | PIGSTY
|
0.0.5 |
18
17
16
15
14
|
postgresql-$v-pg-query-rewrite |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
el8.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
el9.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
el9.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
el10.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
el10.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
d12.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
d12.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
d13.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
d13.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
u22.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
u22.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
u24.x86_64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
u24.aarch64
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
PIGSTY 0.0.5
|
Source
pig build pkg pg_query_rewrite; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_query_rewrite; # install via package name, for the active PG version
pig install pg_query_rewrite -v 18; # install for PG 18
pig install pg_query_rewrite -v 17; # install for PG 17
pig install pg_query_rewrite -v 16; # install for PG 16
pig install pg_query_rewrite -v 15; # install for PG 15
pig install pg_query_rewrite -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_query_rewrite';Create this extension with:
CREATE EXTENSION pg_query_rewrite;Usage
- GitHub Repo:
pierreforstmann/pg_query_rewrite - README: pierreforstmann/pg_query_rewrite/blob/master/README.md
pg_query_rewrite is a PostgreSQL extension that translates an exact source SQL statement into another predefined SQL statement. It must be loaded at server level with shared_preload_libraries, then installed in each database.
The README shows the extension as a simple statement rewrite engine backed by shared-memory rules.
Setup
shared_preload_libraries = 'pg_query_rewrite'
pg_query_rewrite.max_rules = 10CREATE EXTENSION pg_query_rewrite;The README says the extension has been successfully tested with PostgreSQL 9.5 through 18.
Managing Rules
Use the helper functions to manage translations:
SELECT pgqr_add_rule('select 10;', 'select 11;');
SELECT pgqr_remove_rule('select 10;');
SELECT pgqr_truncate();
SELECT pgqr_rules();The example in the README rewrites select 10; to select 11; and then shows the rule list after insertion.
Behavior
- Matching is exact and sensitive to case, spaces, and semicolons.
- Parameterized SQL statements are not supported.
- The maximum SQL statement length is hard-coded at 32K.
- Rules live only in shared memory; the extension does not persist settings on its own.
pg_query_rewrite.max_rulescaps the number of SQL statements that can be translated and defaults to10when unset.
Scope
The upstream README is sufficient here: it covers purpose, server-level loading, rule management, a concrete rewrite example, and the main limitations. No separate docs page or homepage was needed.