plx
plx : Transpile multiple procedural dialects to PL/pgSQL
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | plpgsql plisql plpgsql_wrap orafce db2fce |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| el8.aarch64 | N/A | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| el9.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| el9.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| el10.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| el10.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| d12.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| d12.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| d13.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| d13.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u22.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u22.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u24.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u24.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u26.x86_64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
| u26.aarch64 | MISS | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 | PIGSTY 2.0.1 |
Source
github.com/commandprompt/plx
plx-2.0.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
- PGXN plx 3.0.0 README
- plx 3.0.0 user guide
- plx 3.0.0 compatibility notes
- plx 3.0.0 changelog
- plx control file
plx provides familiar procedural-language dialects that transpile to ordinary PL/pgSQL when CREATE FUNCTION runs. PostgreSQL stores and executes the generated PL/pgSQL with its built-in trusted handler; no Ruby, PHP, JavaScript, Python, Go, COBOL, Oracle, or SQL Server runtime is loaded into the backend.
Available Dialects
| Language | Surface syntax |
|---|---|
plxruby |
Ruby |
plxphp |
PHP |
plxjs |
JavaScript |
plxts |
TypeScript annotations over the JavaScript dialect |
plxpython3 |
Python 3 |
plxgo |
Go |
plxcobol |
ISO COBOL |
plxplsql |
Oracle PL/SQL |
plxtsql |
Transact-SQL |
All dialects target the same PL/pgSQL statement surface, including assignments, conditionals, loops, query iteration, dynamic SQL, cursors, exceptions, triggers, and set-returning functions.
Create a Function
Choose a dialect in the LANGUAGE clause while keeping the function signature in PostgreSQL types:
Translation happens once, when the function is created. The executable body stored in pg_proc.prosrc is regular PL/pgSQL, so it can be dumped, reviewed, and run without a separate interpreter.
Inspect and Debug Generated Code
Runtime error line numbers refer to generated PL/pgSQL. plx_source() recovers the original embedded dialect body; use it together with pg_get_functiondef() when correlating an error with the source.
SQL and String Building
Expressions retain PostgreSQL SQL semantics rather than emulating a complete source-language runtime. Use each dialect’s query/execute form for SQL and explicit PostgreSQL types for non-literal expressions. The plx_strbuild expanded-object helper accelerates repeated string appends on PostgreSQL 18:
The builder remains correct on PostgreSQL 13-17, but its in-place optimization requires PostgreSQL 18.
Boundaries and Caveats
- plx implements syntax surfaces, not the source languages’ runtimes: there are no gems, Python modules, JavaScript imports, Go goroutines, PHP classes, Oracle packages, or SQL Server transaction commands.
- Functions run in PL/pgSQL’s trusted sandbox, with no direct filesystem, network, arbitrary native-code, or transaction-control access.
- Parameters and return types must be PostgreSQL types. Type inference for locals is limited; explicitly declare types for calls and compound expressions.
- SQL uses three-valued logic and PostgreSQL numeric/string semantics. Source-language truthiness and string concatenation with
+are not reproduced. - Locals are hoisted into one PL/pgSQL
DECLAREblock, so block-local scope and redeclaration with a different type are unavailable.
Version 3.0.0 Upgrade
Install the new library and run ALTER EXTENSION plx UPDATE TO '3.0.0', then recreate affected functions from their original dialect DDL. Existing generated PL/pgSQL is not rewritten by the extension update. Keep that source before migration; review functions whose results depend on interpolation, NULL handling or exception exits.
The extension is no longer relocatable. Choose its schema at installation and retain the same schema on restore, or regenerate functions that embed helper names. Creating dialect functions or DO blocks requires USAGE on plpgsql. With function-body checks enabled, creation validates generated PL/pgSQL and rejects unsupported argument/result types and malformed declared types.
Interpolated SQL values are bound as parameters; use ident() for names and restrict deliberate raw() SQL fragments to trusted input. NULL string appends now propagate NULL; use coalesce(x, '') when an empty string is intended. Most dialects now run finally/ensure on return, break and continue, but query cancellation and assertion failures remain outside that handling. Read the dialect-specific breaking changes before redeploying functions.