plx¶
Write PostgreSQL functions in the language you already know. Ruby, PHP,
JavaScript, TypeScript, Python, Go, COBOL, Oracle PL/SQL, or Transact-SQL,
compiled to plpgsql at CREATE FUNCTION time.
plx is a PostgreSQL extension. When you run CREATE FUNCTION ... LANGUAGE plx*,
plx transpiles the body to plpgsql and stores that plpgsql in pg_proc.prosrc.
At run time the function is executed by PostgreSQL's own plpgsql interpreter.
There is no separate language runtime loaded into the backend, the generated
plpgsql is visible in the catalog, and every plpgsql construct is reachable from
every dialect.
CREATE EXTENSION plx;
CREATE FUNCTION grade(score int) RETURNS text LANGUAGE plxruby AS $$
return "A" if score >= 90
return "B" if score >= 80
return "F"
$$;
Dialects¶
The front end is dialect-pluggable, and the set is open-ended. The dialects available today:
- plxruby — a Ruby dialect
- plxphp — a PHP dialect
- plxjs — a JavaScript dialect
- plxts — a TypeScript dialect (plxjs plus type annotations)
- plxpython3 — a Python dialect
- plxgo — a Go dialect
- plxcobol — a COBOL dialect (ISO/IEC 1989:2023)
- plxplsql — an Oracle PL/SQL dialect
- plxtsql — a Transact-SQL (SQL Server) dialect
The user guide shows the same worked examples across dialects, and feature parity is the construct-by-construct matrix.
Why plx¶
- Trusted. A plx function runs as plpgsql and can do exactly what plpgsql can, nothing more. There is no embedded interpreter, unlike the untrusted native PL/Ruby or PL/PHP.
- No new runtime in production. The catalog stores plain plpgsql; nothing new runs in the backend at execution time.
- Familiar syntax, plpgsql performance. Write in the dialect your team knows; run with plpgsql's execution and trust model.
Install¶
Build from source against your PostgreSQL installation:
Then, in the database:
Upgrading from an earlier install:
plx supports PostgreSQL 13 through 18; see compatibility.
More¶
- Architecture and the transpiler specification
- Debugging: correlating runtime errors back to your source
- Source, issues, and releases on GitHub
- Changelog