plr
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3100 | plr | No | Yes | No | Yes | No | Yes | - |
Release/control and current RPM/DEB matrix use 8.4.8.9. Control declares relocatable=true. Local package matrix includes both EL10 architectures for PostgreSQL 14-18.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 8.4.8.9 | 1817161514 | plr | - |
| RPM | PGDG | 8.4.8.9 | 1817161514 | plr_$v | - |
| DEB | PGDG | 8.4.8.9 | 1817161514 | postgresql-$v-plr | - |
Install
You can install plr directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
plr enables writing PostgreSQL functions in the R programming language, providing full access to R’s statistical and data analysis capabilities.
Create Functions
With named arguments:
Argument Handling
- Unnamed arguments are available as
arg1,arg2, …; an explicitly named parameter replaces its correspondingargNvariable. - Scalar SQL NULL becomes R NULL; null array elements become R
NA. ASTRICTfunction skips calls with a whole NULL argument, not arrays containing null elements. - Composite types (rows) are passed as R data.frames
- One-dimensional arrays become R vectors; two-dimensional arrays become matrices and three-dimensional arrays become R arrays. Higher dimensions are unsupported.
Database Access via SPI
Initialize the type OID variables in the same connection before calling a function that prepares a parameterized query:
Set-Returning Functions
Return an R vector for a set of scalar values:
Window Functions
Window functions receive farg1..fargN (vectors of values in the window frame), fnumrows (frame size), and prownum (current row position in partition).
Global Variables
Persist data across function calls using R’s global environment:
Useful Support Functions
Trigger Functions
PL/R supports trigger functions with access to pg.tg.name, pg.tg.relname, pg.tg.when, pg.tg.level, pg.tg.op, pg.tg.new, and pg.tg.old.
Runtime and Privileges
This page follows PL/R 8.4.8.7. PL/R is an untrusted language: creating its functions requires a superuser, and R code runs with the PostgreSQL operating-system user’s access to files and processes. Review function bodies and EXECUTE grants accordingly. The R shared library must be available, and upstream requires R_HOME in the PostgreSQL server process environment before startup on Unix systems. Adding it only to an interactive client shell does not configure the server.
SQL scalar NULL converts to R NULL, while null elements within an array convert to R NA; declaring a function STRICT prevents calls with null arguments. R global state belongs to a backend process, not to all sessions or to a durable database table. Upstream revokes PUBLIC execution of environment-changing helpers including plr_set_rhome(text); use an administrator-managed runtime rather than exposing these helpers to application roles. Normal usage does not require shared preload.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)