pg_fsql
pg_fsql : Recursive SQL template engine with JSONB-driven execution
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4110 | pg_fsql
|
pg_fsql
|
1.1.0 |
UTIL
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | fsql |
| Requires | plpgsql
|
| See Also | plpgsql
pg_readme
schedoc
|
Release tag 1.1.0 still ships extension SQL version 1.0; shared_preload_libraries is optional and only needed for session-start GUC availability.
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.1.0 |
18
17
16
15
14
|
pg_fsql |
plpgsql |
| RPM | PIGSTY
|
1.1.0 |
18
17
16
15
14
|
pg_fsql_$v |
- |
| DEB | PIGSTY
|
1.1.0 |
18
17
16
15
14
|
postgresql-$v-pg-fsql |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
el8.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
el9.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
el9.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
el10.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
el10.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
d12.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
d12.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
d13.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
d13.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u22.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u22.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u24.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u24.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u26.x86_64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
u26.aarch64
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
PIGSTY 1.1.0
|
Source
pig build pkg pg_fsql; # 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_fsql; # install via package name, for the active PG version
pig install pg_fsql -v 18; # install for PG 18
pig install pg_fsql -v 17; # install for PG 17
pig install pg_fsql -v 16; # install for PG 16
pig install pg_fsql -v 15; # install for PG 15
pig install pg_fsql -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_fsql CASCADE; -- requires plpgsqlUsage
Sources: README, control file
pg_fsql is a recursive SQL template engine for PostgreSQL. It combines a C-based placeholder renderer with PL/pgSQL template execution, hierarchical template composition, and optional SPI plan caching. The upstream project emphasizes that it does not require superuser privileges.
Quick Start
CREATE EXTENSION pg_fsql;
INSERT INTO fsql.templates (path, cmd, body)
VALUES ('user_count', 'exec',
'SELECT jsonb_build_object(''total'', count(*))
FROM users WHERE status = {d[status]!r}');
SELECT fsql.run('user_count', '{"status":"active"}');
SELECT fsql.render('user_count', '{"status":"active"}');Catalog Tables
The extension installs two main catalog tables:
fsql.templates (
path varchar(500) primary key,
cmd varchar(50),
body text,
defaults text,
cached boolean default false
)
fsql.params (
key_param varchar(255) primary key,
type_param varchar(255) not null
)path is dot-separated and defines the template hierarchy.
Commands and Placeholders
The README documents six command types:
execto execute SQL and returnjsonbrefto redirect to another templateifto choose a child branchexec_tplto execute SQL and re-render the result as a templatemapto collect children into a JSON objectNULLfor text fragments inserted into parents
The renderer supports placeholders such as:
{d[key]}{d[key]!r}forquote_literal{d[key]!j}for JSONB literals{d[key]!i}forquote_identifier
The special key _self injects the full input JSON object.
Public API
The upstream public functions include:
fsql.run(path, data, debug)to execute a template treefsql.render(path, data)to preview rendered SQLfsql.tree(path)to inspect hierarchyfsql.explain(path, data)to trace expansionfsql.validate()to check templatesfsql.depends_on(path)to inspect dependenciesfsql.clear_cache()to free cached SPI plans
Hierarchical Example
INSERT INTO fsql.templates (path, cmd, body) VALUES
('report', 'exec',
'SELECT jsonb_build_object(''data'', array_agg(row_to_json(t)))
FROM (SELECT {d[cols]} FROM {d[src]} {d[where]}) t'),
('report.cols', NULL, 'id, name, email'),
('report.src', NULL, 'customers'),
('report.where', NULL, 'WHERE city = {d[city]!r}');
SELECT fsql.run('report', '{"city":"Moscow"}');
SELECT fsql.render('report', '{"city":"Moscow"}');Notes
The README lists PostgreSQL 14+ and plpgsql. The control file currently declares SQL extension version 1.0, even though the package task tracks release 1.1.0. No official release notes were published in the repository; the user-facing README still documents the same core API and behavior.