pg_query_rewrite
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 |
u26.x86_64 | PIGSTY 0.0.5 | PIGSTY 0.0.5 | PIGSTY 0.0.5 | PIGSTY 0.0.5 | PIGSTY 0.0.5 |
u26.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
Source: README
pg_query_rewrite rewrites an exact source SQL statement into a predefined target statement using rules stored in shared memory.
Required setup
-- postgresql.conf
shared_preload_libraries = 'pg_query_rewrite'
pg_query_rewrite.max_rules = 10
CREATE EXTENSION pg_query_rewrite;Rule management
SELECT pgqr_add_rule('select 10;', 'select 11;');
SELECT pgqr_rules();
SELECT pgqr_remove_rule('select 10;');
SELECT pgqr_truncate();pgqr_add_rule(source, target): add a rewrite rule.pgqr_remove_rule(source): remove one rule.pgqr_truncate(): remove all rules.pgqr_rules(): inspect current shared-memory rules and rewrite counts.
Caveats
- Matching is exact: case, whitespace, and semicolons must match character-for-character.
- Parameterized SQL is not supported.
- Maximum statement length is hard-coded at 32 KB.
- Rules are not persisted; they vanish on restart unless you reapply them.
Last updated on