跳转到主要内容

pg_grammar_guard

根据实时目录生成语法并检测已批准语法的漂移

概览

扩展包名版本分类许可证语言
pg_grammar_guard0.4.1RAGPostgreSQLSQL
ID扩展名BinLibLoadCreateTrustReloc模式
1890pg_grammar_guard否否否是否否grammar_guard

Requires pg_living_assertions, despite older README text claiming no dependencies.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.4.11817161514pg_grammar_guardpg_living_assertions
RPMPIGSTY0.4.11817161514pg_grammar_guard_$vpg_living_assertions_$v
DEBPIGSTY0.4.11817161514postgresql-$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

构建

您可以使用 pig build 命令构建 pg_grammar_guard 扩展的 RPM / DEB 包:

pig build pkg pg_grammar_guard         # 构建 RPM / DEB 包

安装

您可以直接安装 pg_grammar_guard 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install pg_grammar_guard;          # 当前活跃 PG 版本安装
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 pg_grammar_guard CASCADE;  -- 依赖: pg_living_assertions

用法

来源:

pg_grammar_guard 根据目录中的标识符生成 GBNF 或 JSON Schema,并检测已批准语法的漂移。它是无需预加载的纯 SQL 扩展,本包支持 PostgreSQL 14–18。control 文件明确依赖 pg_living_assertions。

生成语法

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[]);

目录辅助函数枚举实际存在的表、列和枚举标签。生成器支持嵌套对象和有界数组;任意 SQL、文件路径等开放集合仍需单独验证。

检测变化

grammar_guard.watch() 保存用于重建语法的查询,grammar_guard.check_grammar() 依据实时目录执行检查。可通过 living_assertions.status 查看结果及其年龄。

只有受信任的管理员才应登记基线 SQL。语法能限制合法标识符,无法证明选择的表、关联或答案在语义上正确。旧 0.2 系列基线缺少原始生成查询,升级时需要人工重新批准。

这个页面对您有帮助吗?