plr
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3100 | plr | No | Yes | No | Yes | No | No | - |
missing el10.x86_64
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 8.4.8.6 | 1817161514 | plr | - |
| RPM | PGDG | 8.4.8.6 | 1817161514 | plr_$v | - |
| DEB | PGDG | 8.4.8.6 | 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
plr: load R interpreter and execute R script from within a database
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
- Arguments are available as
arg1,arg2, … or by named parameter - NULL arguments become R
NAvalues (unless function isSTRICT) - Composite types (rows) are passed as R data.frames
- Arrays are passed as R vectors
Database Access via SPI
Prepared statements:
Set-Returning Functions
Return a data.frame for set-returning functions:
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.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)