Registry / database / plpgsql-deparser

plpgsql-deparser

JSON →
library0.7.7jsnpmunverified

Converts parsed PL/pgSQL function ASTs back into SQL source code. Part of the pgsql-parser ecosystem. v0.7.7 (stable, weekly releases). Key differentiator: round-tripping from AST to SQL with high fidelity, supporting PostgreSQL's PL/pgSQL dialect including complex control structures. Depends on libpg_query for parsing; you must parse first with pgsql-parser.

npm install plpgsql-deparser
INSTALL
IMPORT
SIG · PLPGSQL-DEPARSER
P
plpgsql-deparser
databasejavascriptv0.7.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deparse
import { deparse } from 'plpgsql-deparser'
const deparse = require('plpgsql-deparser')
ESM-only. CommonJS require will not work; use import or dynamic import.
deparse
import { deparse } from 'plpgsql-deparser'
import deparse from 'plpgsql-deparser'
Named export, not default.
PlPgSqlStatements
import { PlPgSqlStatements } from 'plpgsql-deparser'
TypeScript type export for the AST node types.

Parses a PL/pgSQL function and then deparses it back to SQL.

import { parsePlPgSql } from 'pgsql-parser'; import { deparse } from 'plpgsql-deparser'; const sql = `CREATE OR REPLACE FUNCTION add(a INT, b INT) RETURNS INT AS $$ BEGIN RETURN a + b; END; $$ LANGUAGE plpgsql;`; const parsed = parsePlPgSql(sql); const deparsed = deparse(parsed); console.log('Deparsed SQL:'); console.log(deparsed);
Debug
Known issues
gotchaDeparser expects AST from pgsql-parser's parsePlPgSql only; parsing with other libraries will fail.
fix
Always use parsePlPgSql from pgsql-parser.
affects: >=0.0.0
gotchaNot all PL/pgSQL constructs are supported; some may be omitted or produce different SQL.
fix
Check the documentation for known limitations; test round-tripping.
affects: <1.0.0
breakingVersion 0.7.0 changed internal AST node names; deparse may fail with ASTs from older parser versions.
fix
Ensure pgsql-parser is also v0.7.x.
affects: 0.7.0 - 0.7.7
Errors
Common errors & fixes
TypeError: deparse is not a function
Default import used instead of named import.
fix
import { deparse } from 'plpgsql-deparser'
Error: Expected AST from parsePlPgSql, got undefined
Called deparse without parsing first, or parsed with wrong function.
fix
Use pgsql-parser's parsePlPgSql to parse the SQL before deparsing.
Cannot find module 'plpgsql-deparser' or its corresponding type declarations.
Package not installed or TypeScript cannot find types. Ensure it is installed and tsconfig includes node_modules.
fix
npm install plpgsql-deparser
Upgrade
Version history
0.7.7latest on npm
Audit
Dependencies
pgsql-parserrequiredProduces the AST that plpgsql-deparser consumes.
Agent activity
2 hits · last 30 days
node
2
Resources
plpgsql-deparser — npm install plpgsql-deparser · libregistry