pg_mustach
pg_mustach · PostgreSQL implementation of Mustache templating
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100363 | pg_mustach | pg_mustach | 2.0 | UTIL | MIT | C |
Usage
Sources:
pg_mustach 2.0 renders Mustache templates from jsonb through libmustach 2 or newer. It adds prepared templates and replaces the older JSON-library-specific adapters with a unified interface.
Core Workflow
Templates and Flags
mustach renders directly. mustach_template prepares a named template or the unnamed slot; mustach_json renders it, and mustach_free releases it. Use the named argument tplname explicitly: a positional second text argument can resolve to the file-writing overload instead.
pg_mustach.transaction defaults to true, so prepared templates are cleared at transaction end. A preparation in one autocommit statement will not survive to the next statement. Set it false only when intentionally managing session-local lifetime, especially with connection pools. pg_mustach.flags and mustach_set_flags control rendering flags; mustach_with_* helpers return flag values.
Upgrade and Access
The control version is 2.0, while the PGXN distribution is 2.0.0. Review the shipped upgrade SQL before migrating applications from json adapters to jsonb. File-output overloads write on the server and require superuser privileges. The extension is relocatable and needs no preload. Bound template size and output volume for untrusted inputs.
Local-file partials are separately controlled by the superuser-only pg_mustach.whitelist prefix list. Ordinary roles need an explicit matching grant; a nonempty list also restricts superusers. The whitelist does not authorize file-output overloads.