lua_fdw
lua_fdw · Lua Foreign Data Wrapper
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100369 | lua_fdw | lua_fdw | 0.0.1 | FDW | PostgreSQL | C |
Usage
Sources:
lua_fdw version 0.0.1 lets a server-side Lua script implement a read-only PostgreSQL foreign table. Use it as an adapter for data sources that can be reached from Lua, with the important boundary that the script executes inside a PostgreSQL backend.
Core Workflow
A minimal script returns one row:
Point a foreign table at the server-side file:
Lua API
Planning callbacks are EstimateRowCount(), EstimateRowWidth(), EstimateStartupCost(), and EstimateTotalCost(). Scan callbacks are ScanStart(), ScanIterate(), ScanRestart(), ScanEnd(), and ScanExplain(); missing callbacks are skipped.
The global fdw table exposes fdw.table, fdw.columns, fdw.clauses, and fdw.ereport(). Simple top-level WHERE clauses appear in fdw.clauses, but the Lua script must apply any remote filtering itself.
Options and Security
script selects the Lua file. inject executes an additional Lua fragment after loading it; lua_path and lua_cpath extend Lua module search paths. These are code-execution capabilities, not data-only options. Lua code runs with the PostgreSQL backend’s operating-system access, and lua_cpath can load native modules. Restrict ownership and FDW/server usage to trusted administrators, keep scripts immutable to untrusted users, and do not treat the runtime as a sandbox. The FDW supplies scan callbacks only and does not implement SQL writes.