plpgsql-internalslisted
Install: claude install-skill matejformanek/postgres-claude
# plpgsql-internals — the SQL procedural language
PL/pgSQL is PG's most-used procedural language: functions, procedures, DO blocks, triggers. Under the hood it's a **parser + compiler + interpreter** living in a self-contained subdirectory. The interpreter (`pl_exec.c`) is 268 KB — the biggest source file in PG core after `postmaster.c`.
## The file map
| File | KB | Role |
|---|---:|---|
| `pl_handler.c` | 15 | The `PL_handler_*` fmgr entry points. Compiles + caches + executes. **This is where the trusted-language sandbox gate lives — enforced exactly twice.** |
| `pl_gram.y` | 119 | Bison grammar — PL/pgSQL statement syntax (IF / LOOP / WHILE / FOR / DECLARE / RAISE / GET DIAGNOSTICS / etc.). |
| `pl_scanner.c` | 19 | Tokenizer that feeds the grammar. Wraps `core_yylex` — shares tokens with the main SQL parser. |
| `pl_comp.c` | 66 | Compiler — takes the parsed AST + turns it into `PLpgSQL_function` struct with `PLpgSQL_stmt`s + datum types + variable slots. |
| `pl_exec.c` | **268** | Interpreter. `exec_stmt_block`, `exec_stmt_execsql`, `exec_stmt_return`, `exec_stmt_raise`, EXCEPTION handling. Every statement type has its own `exec_stmt_*` handler. |
| `pl_funcs.c` | 39 | Utility functions — data structures, formatting, err-context callback, dumping compiled functions. |
| `plpgsql.h` | 37 | Public API + PLpgSQL_* struct definitions. |
| `pl_reserved_kwlist.h` + `pl_unreserved_kwlist.h` | — | Keyword tables. PL/pgSQL has its own reserved-word set separate from SQL. |