pg_render
pg_render
pg_render : Render HTML in SQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4290 | pg_render
|
pg_render
|
0.1.3 |
UTIL
|
MIT
|
Rust
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--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
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| 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 / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
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
|
Source
pig build pkg pg_render; # 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_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 14Create this extension with:
CREATE EXTENSION pg_render;Usage
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