Skip to content
pg_render

pg_render

pg_render : Render HTML in SQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4290
pg_render
pg_render
0.1.3
UTIL
MIT
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
See Also
pg_html5_email_address
pg_readme
gzip
bzip
zstd
http
pg_net
pg_curl

manual updated pgrx by Vonng

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.1.3
18
17
16
15
14
pg_render-
RPM
PIGSTY
0.1.3
18
17
16
15
14
pg_render_$v-
DEB
PIGSTY
0.1.3
18
17
16
15
14
postgresql-$v-pg-render-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
el8.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
el9.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
el9.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
el10.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
el10.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
d12.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
d12.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
d13.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
d13.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
u22.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
u22.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
u24.x86_64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
u24.aarch64
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
PIGSTY 0.1.3
u26.x86_64
MISS
MISS
MISS
MISS
MISS
u26.aarch64
MISS
MISS
MISS
MISS
MISS
PackageVersionOSORGSIZEFile URL
pg_render_180.1.3el8.x86_64pigsty1.1 MiBpg_render_18-0.1.3-1PIGSTY.el8.x86_64.rpm
pg_render_180.1.3el8.aarch64pigsty906.8 KiBpg_render_18-0.1.3-1PIGSTY.el8.aarch64.rpm
pg_render_180.1.3el9.x86_64pigsty1.1 MiBpg_render_18-0.1.3-1PIGSTY.el9.x86_64.rpm
pg_render_180.1.3el9.aarch64pigsty970.5 KiBpg_render_18-0.1.3-1PIGSTY.el9.aarch64.rpm
pg_render_180.1.3el10.x86_64pigsty1.1 MiBpg_render_18-0.1.3-1PIGSTY.el10.x86_64.rpm
pg_render_180.1.3el10.aarch64pigsty988.4 KiBpg_render_18-0.1.3-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-render0.1.3d12.x86_64pigsty903.5 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-render0.1.3d12.aarch64pigsty709.4 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-render0.1.3d13.x86_64pigsty903.6 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-render0.1.3d13.aarch64pigsty709.1 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-render0.1.3u22.x86_64pigsty1014.7 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-render0.1.3u22.aarch64pigsty847.6 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-render0.1.3u24.x86_64pigsty1013.0 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~noble_amd64.deb
postgresql-18-pg-render0.1.3u24.aarch64pigsty841.3 KiBpostgresql-18-pg-render_0.1.3-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_render;		# 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_render;		# install via package name, for the active PG version

pig install pg_render -v 18;   # install for PG 18
pig install pg_render -v 17;   # install for PG 17
pig install pg_render -v 16;   # install for PG 16
pig install pg_render -v 15;   # install for PG 15
pig install pg_render -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_render;

Usage

pg_render: Liquid template rendering for PostgreSQL

render(template text, input json|array|value)

Render a template with query results using Liquid syntax:

-- Single value
SELECT render('Total: {{ value }}', (SELECT count(*) FROM posts));

-- Multiple columns from one row
SELECT render(
    '<h1>{{ title }}</h1><p>{{ text }}</p>',
    (SELECT to_json(r) FROM (SELECT title, text FROM posts WHERE id = 1) r)
);

-- Loop over an array
SELECT render(
    '{% for v in values %} {{ v }} {% endfor %}',
    (SELECT array(SELECT title FROM posts))
);

-- Loop over multiple rows with multiple columns
SELECT render(
    '{% for row in rows %} {{ row.title }} - {{ row.author }} {% endfor %}',
    json_agg(to_json(posts.*))
) FROM posts;

render_agg(template text, input record|json|value)

Aggregate render function – renders a template for each row:

-- Render each row from a derived table
SELECT render_agg('{{ title }} {{ text }}', props)
FROM (SELECT title, text FROM posts) AS props;

-- Render using json_build_object
SELECT render_agg(
    '<article><h1>{{ title }}</h1></article>',
    json_build_object('title', title)
) FROM posts;

Using Stored Templates

SELECT render(
    (SELECT template FROM templates WHERE id = 'my_tpl'),
    (SELECT to_json(r) FROM (SELECT title, text FROM posts WHERE id = 1) r)
);

PostgREST Integration

CREATE FUNCTION api.index() RETURNS "text/html" AS $$
SELECT render(
    '<html><body><h1>{{ title }}</h1></body></html>',
    (SELECT to_json(r) FROM (SELECT title FROM posts WHERE id = 1) r)
) $$;
Last updated on