Skip to content

pg_fsql

Recursive SQL template engine with JSONB-driven execution

pg_fsql · Recursive SQL template engine with JSONB-driven execution

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4110pg_fsqlpg_fsql1.1.0UTILPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--NoYesNoYesnono
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

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.1.019 18 17 16 15pg_fsqlplpgsql
RPMPIGSTY1.1.019 18 17 16 15pg_fsql_$v-
DEBPIGSTY1.1.019 18 17 16 15postgresql-$v-pg-fsql-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el8.aarch64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
PackageVersionOSORGSIZEFile URL
pg_fsql_191.1.0el9.x86_64pigsty33.2 KiBpg_fsql_19-1.1.0-1PGSTY.el9.x86_64.rpm
pg_fsql_191.1.0el9.aarch64pigsty33.2 KiBpg_fsql_19-1.1.0-1PGSTY.el9.aarch64.rpm
pg_fsql_191.1.0el10.x86_64pigsty33.4 KiBpg_fsql_19-1.1.0-1PGSTY.el10.x86_64.rpm
pg_fsql_191.1.0el10.aarch64pigsty33.3 KiBpg_fsql_19-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-fsql1.1.0d12.x86_64pigsty24.8 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-fsql1.1.0d12.aarch64pigsty25.0 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-fsql1.1.0d13.x86_64pigsty24.8 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-fsql1.1.0d13.aarch64pigsty25.0 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-fsql1.1.0u22.x86_64pigsty25.2 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-fsql1.1.0u22.aarch64pigsty25.1 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-fsql1.1.0u24.x86_64pigsty24.9 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-fsql1.1.0u24.aarch64pigsty25.2 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-fsql1.1.0u26.x86_64pigsty25.0 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-fsql1.1.0u26.aarch64pigsty24.8 KiBpostgresql-19-pg-fsql_1.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_fsql_181.1.0el8.x86_64pigsty32.7 KiBpg_fsql_18-1.1.0-1PGSTY.el8.x86_64.rpm
pg_fsql_181.1.0el8.aarch64pigsty32.8 KiBpg_fsql_18-1.1.0-1PGSTY.el8.aarch64.rpm
pg_fsql_181.1.0el9.x86_64pigsty33.2 KiBpg_fsql_18-1.1.0-1PGSTY.el9.x86_64.rpm
pg_fsql_181.1.0el9.aarch64pigsty33.1 KiBpg_fsql_18-1.1.0-1PGSTY.el9.aarch64.rpm
pg_fsql_181.1.0el10.x86_64pigsty33.4 KiBpg_fsql_18-1.1.0-1PGSTY.el10.x86_64.rpm
pg_fsql_181.1.0el10.aarch64pigsty33.3 KiBpg_fsql_18-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-fsql1.1.0d12.x86_64pigsty24.7 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-fsql1.1.0d12.aarch64pigsty24.9 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-fsql1.1.0d13.x86_64pigsty24.8 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-fsql1.1.0d13.aarch64pigsty25.0 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-fsql1.1.0u22.x86_64pigsty25.2 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-fsql1.1.0u22.aarch64pigsty25.1 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-fsql1.1.0u24.x86_64pigsty24.8 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-fsql1.1.0u24.aarch64pigsty25.1 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-fsql1.1.0u26.x86_64pigsty24.9 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-fsql1.1.0u26.aarch64pigsty24.9 KiBpostgresql-18-pg-fsql_1.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_fsql_171.1.0el8.x86_64pigsty32.6 KiBpg_fsql_17-1.1.0-1PGSTY.el8.x86_64.rpm
pg_fsql_171.1.0el8.aarch64pigsty32.8 KiBpg_fsql_17-1.1.0-1PGSTY.el8.aarch64.rpm
pg_fsql_171.1.0el9.x86_64pigsty33.1 KiBpg_fsql_17-1.1.0-1PGSTY.el9.x86_64.rpm
pg_fsql_171.1.0el9.aarch64pigsty33.1 KiBpg_fsql_17-1.1.0-1PGSTY.el9.aarch64.rpm
pg_fsql_171.1.0el10.x86_64pigsty33.3 KiBpg_fsql_17-1.1.0-1PGSTY.el10.x86_64.rpm
pg_fsql_171.1.0el10.aarch64pigsty33.2 KiBpg_fsql_17-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-fsql1.1.0d12.x86_64pigsty24.7 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-fsql1.1.0d12.aarch64pigsty24.9 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-fsql1.1.0d13.x86_64pigsty24.7 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-fsql1.1.0d13.aarch64pigsty25.0 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-fsql1.1.0u22.x86_64pigsty26.4 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-fsql1.1.0u22.aarch64pigsty26.4 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-fsql1.1.0u24.x86_64pigsty24.8 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-fsql1.1.0u24.aarch64pigsty25.1 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-fsql1.1.0u26.x86_64pigsty24.9 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-fsql1.1.0u26.aarch64pigsty24.8 KiBpostgresql-17-pg-fsql_1.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_fsql_161.1.0el8.x86_64pigsty32.6 KiBpg_fsql_16-1.1.0-1PGSTY.el8.x86_64.rpm
pg_fsql_161.1.0el8.aarch64pigsty32.8 KiBpg_fsql_16-1.1.0-1PGSTY.el8.aarch64.rpm
pg_fsql_161.1.0el9.x86_64pigsty33.2 KiBpg_fsql_16-1.1.0-1PGSTY.el9.x86_64.rpm
pg_fsql_161.1.0el9.aarch64pigsty33.1 KiBpg_fsql_16-1.1.0-1PGSTY.el9.aarch64.rpm
pg_fsql_161.1.0el10.x86_64pigsty33.3 KiBpg_fsql_16-1.1.0-1PGSTY.el10.x86_64.rpm
pg_fsql_161.1.0el10.aarch64pigsty33.2 KiBpg_fsql_16-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-fsql1.1.0d12.x86_64pigsty24.7 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-fsql1.1.0d12.aarch64pigsty24.8 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-fsql1.1.0d13.x86_64pigsty24.7 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-fsql1.1.0d13.aarch64pigsty25.0 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-fsql1.1.0u22.x86_64pigsty26.4 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-fsql1.1.0u22.aarch64pigsty26.4 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-fsql1.1.0u24.x86_64pigsty24.8 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-fsql1.1.0u24.aarch64pigsty25.1 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-fsql1.1.0u26.x86_64pigsty24.9 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-fsql1.1.0u26.aarch64pigsty24.8 KiBpostgresql-16-pg-fsql_1.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_fsql_151.1.0el8.x86_64pigsty32.7 KiBpg_fsql_15-1.1.0-1PGSTY.el8.x86_64.rpm
pg_fsql_151.1.0el8.aarch64pigsty32.8 KiBpg_fsql_15-1.1.0-1PGSTY.el8.aarch64.rpm
pg_fsql_151.1.0el9.x86_64pigsty33.2 KiBpg_fsql_15-1.1.0-1PGSTY.el9.x86_64.rpm
pg_fsql_151.1.0el9.aarch64pigsty33.1 KiBpg_fsql_15-1.1.0-1PGSTY.el9.aarch64.rpm
pg_fsql_151.1.0el10.x86_64pigsty33.3 KiBpg_fsql_15-1.1.0-1PGSTY.el10.x86_64.rpm
pg_fsql_151.1.0el10.aarch64pigsty33.3 KiBpg_fsql_15-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-fsql1.1.0d12.x86_64pigsty24.8 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-fsql1.1.0d12.aarch64pigsty25.0 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-fsql1.1.0d13.x86_64pigsty24.8 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-fsql1.1.0d13.aarch64pigsty25.0 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-fsql1.1.0u22.x86_64pigsty26.5 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-fsql1.1.0u22.aarch64pigsty26.4 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-fsql1.1.0u24.x86_64pigsty24.8 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-fsql1.1.0u24.aarch64pigsty25.2 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-fsql1.1.0u26.x86_64pigsty24.9 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-fsql1.1.0u26.aarch64pigsty24.8 KiBpostgresql-15-pg-fsql_1.1.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_fsql;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_fsql;		# install by package name

pig install pg_fsql -v 19;   # install for PG 19
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

Create this extension with:

CREATE EXTENSION pg_fsql CASCADE; -- requires plpgsql

Usage

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:

  • exec to execute SQL and return jsonb
  • ref to redirect to another template
  • if to choose a child branch
  • exec_tpl to execute SQL and re-render the result as a template
  • map to collect children into a JSON object
  • NULL for text fragments inserted into parents

The renderer supports placeholders such as:

  • {d[key]}
  • {d[key]!r} for quote_literal
  • {d[key]!j} for JSONB literals
  • {d[key]!i} for quote_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 tree
  • fsql.render(path, data) to preview rendered SQL
  • fsql.tree(path) to inspect hierarchy
  • fsql.explain(path, data) to trace expansion
  • fsql.validate() to check templates
  • fsql.depends_on(path) to inspect dependencies
  • fsql.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.

Table reader