plsh
PL/sh procedural language
plsh : PL/sh procedural language
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3080 | plsh | plsh | 1.20220917 |
LANG | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| el8.aarch64 | N/A | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| el9.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| el9.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| el10.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| el10.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| d12.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| d12.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| d13.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| d13.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u22.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u22.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u24.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u24.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u26.x86_64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
| u26.aarch64 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 | PGDG 1.20220917 |
Source
github.com/petere/plsh
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
Usage
plsh allows writing PostgreSQL functions as shell scripts. The function body must start with a shebang line specifying the interpreter.
Create Shell Functions
Argument Passing
Function arguments are passed as positional shell variables ($1, $2, etc.):
Return Values
- Standard output becomes the return value (trailing newlines stripped)
- Empty output returns NULL
- Standard error output causes the function to abort with that error message
- Non-zero exit status triggers an error
Database Access
Direct SPI access is not available, but psql can be used since libpq environment variables are preconfigured:
Trigger Functions
Trigger context is available via environment variables:
| Variable | Description |
|---|---|
PLSH_TG_NAME |
Trigger name |
PLSH_TG_WHEN |
BEFORE, INSTEAD OF, or AFTER |
PLSH_TG_LEVEL |
ROW or STATEMENT |
PLSH_TG_OP |
DELETE, INSERT, UPDATE, or TRUNCATE |
PLSH_TG_TABLE_NAME |
Target table name |
PLSH_TG_TABLE_SCHEMA |
Target table schema |
Event trigger variables: PLSH_TG_EVENT, PLSH_TG_TAG.
Inline Execution
Security
plsh should not be declared as TRUSTED since shell scripts have full OS-level access under the PostgreSQL user. Only superusers should create plsh functions.