Skip to content

pgcel

Evaluate Common Expression Language programs against JSON values

pgcel · Evaluate Common Expression Language programs against JSON values

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102108pgcelpgcel0.1.0LANGMITRust

PostgreSQL · 14, 15, 16, 17

Usage

Sources:

pgcel stores CEL expression source in the celprogram type and evaluates it against a JSONB context. Use it for reusable predicates or calculations inside SQL. The implementation registers shared memory during initialization, so preload the library and restart before use.

Core Workflow

shared_preload_libraries = 'pgcel'
CREATE EXTENSION pgcel;
SELECT cel_eval(cel_compile('ctx.age >= 18'), '{"age": 21}'::jsonb);
SELECT cel_eval_json(cel_compile('ctx.a + ctx.b'), '{"a": 1, "b": 2}'::jsonb);
SET pgcel.program_cache_size = 2048;

Operational Boundaries

cel_compile validates source, cel_eval requires a boolean result, and cel_eval_json returns other results as JSONB. The input object is available as ctx; invalid expressions, missing values or incompatible result types can raise errors. PostgreSQL build features cover 14–17. The control file is non-relocatable and sets superuser=false; normal database/object privileges still apply. pgcel.program_cache_size defaults to 1024 compiled programs per backend and accepts 1–65536. Shared memory holds only validation hashes, not executable programs; every backend compiles its own executable. Size connection pools and caches accordingly. This early release is not a replacement for PostgreSQL role privileges or RLS.

Table reader