Skip to content

pg_grammar_guard

Catalog-derived grammars and approved grammar drift checks

Overview

PackageVersionCategoryLicenseLanguage
pg_grammar_guard0.4.9RAGApache-2.0SQL
IDExtensionBinLibLoadCreateTrustRelocSchema
1890pg_grammar_guardNoNoNoYesNoNogrammar_guard

Requires pg_living_assertions >= 0.5.9.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.4.91817161514pg_grammar_guardpg_living_assertions
RPMPIGSTY0.4.91817161514pg_grammar_guard_$vpg_living_assertions_$v
DEBPIGSTY0.4.91817161514postgresql-$v-pg-grammar-guardpostgresql-$v-pg-living-assertions
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
el8.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
el9.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
el9.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
el10.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
el10.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
d12.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
d12.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
d13.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
d13.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u22.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u22.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u24.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u24.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u26.x86_64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
u26.aarch64
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1
PIGSTY 0.4.1

Build

You can build the RPM / DEB packages for pg_grammar_guard using pig build:

pig build pkg pg_grammar_guard         # build RPM / DEB packages

Install

You can install pg_grammar_guard 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:

Install
pig install pg_grammar_guard;          # Install for current active PG version
pig
pig ext install -y pg_grammar_guard -v 18  # PG 18
pig ext install -y pg_grammar_guard -v 17  # PG 17
pig ext install -y pg_grammar_guard -v 16  # PG 16
pig ext install -y pg_grammar_guard -v 15  # PG 15
pig ext install -y pg_grammar_guard -v 14  # PG 14
dnf
dnf install -y pg_grammar_guard_18       # PG 18
dnf install -y pg_grammar_guard_17       # PG 17
dnf install -y pg_grammar_guard_16       # PG 16
dnf install -y pg_grammar_guard_15       # PG 15
dnf install -y pg_grammar_guard_14       # PG 14
apt
apt install -y postgresql-18-pg-grammar-guard   # PG 18
apt install -y postgresql-17-pg-grammar-guard   # PG 17
apt install -y postgresql-16-pg-grammar-guard   # PG 16
apt install -y postgresql-15-pg-grammar-guard   # PG 15
apt install -y postgresql-14-pg-grammar-guard   # PG 14

Create Extension:

CREATE EXTENSION pg_grammar_guard CASCADE;  -- requires: pg_living_assertions

Usage

Sources:

pg_grammar_guard 0.4.8 creates GBNF or JSON Schema from catalog identifiers and watches approved grammars for drift. It is pure SQL and requires pg_living_assertions 0.5.9 or later.

Core Workflow

CREATE EXTENSION pg_grammar_guard CASCADE;
CREATE TABLE public.grammar_demo (id integer, label text);
SELECT grammar_guard.grammar_for_json(ARRAY[
  ROW('column', 'enum',
      grammar_guard.catalog_columns('public.grammar_demo'), true)
]::grammar_guard.grammar_field[]);

Operational Boundaries

grammar_guard.catalog_tables() and grammar_guard.catalog_columns() expose catalog names; grammar_guard.grammar_for_json() assembles typed fields, nested structures and bounded arrays. grammar_guard.watch() records the SQL that regenerates a grammar, and grammar_guard.check_grammar() compares it with the approved state in living_assertions.status. The generating query resolves with its author search path and executes as that author. Input NULLs, empty/duplicate field names, empty pivots and invalid bounds are rejected; max_items is capped at 1000. Version 0.4.8 changes canonical fingerprints, and the ordered catalog list can make an existing watch fail once: inspect and re-approve it. A grammar controls allowed tokens, not semantic correctness or authorization. Register trusted SQL only. No preload is required. Current Apache-2.0 licensing begins at 0.4.4; earlier releases retain their original license.

Was this page helpful?