This is the official PostgreSQL parser, compiled to WebAssembly (WASM) for seamless, cross-platform compatibility. Use it in Node.js or the browser, on Linux, Windows, or anywhere JavaScript runs.
Built to power pgsql-parser, this library delivers full fidelity with the Postgres C codebase β no rewrites, no shortcuts.
π― Want to parse + deparse (full round trip)?
We highly recommend usingpgsql-parserwhich leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query.
Need to support multiple PostgreSQL versions at runtime?
Use@pgsql/parserfor dynamic version selection β parse SQL with PostgreSQL 15, 16, 17, or 18 in a single package!import { parse } from '@pgsql/parser'; // Parse with specific PostgreSQL version const result15 = await parse('SELECT * FROM users', 15); const result18 = await parse('SELECT * FROM users', 18);
npm install libpg-query
import { parse } from 'libpg-query';
const result = await parse('SELECT * FROM users WHERE active = true');
// {"version":180004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]}
This repository contains multiple packages to support different PostgreSQL versions and use cases:
| Package | Description | PostgreSQL Versions | npm Package |
|---|---|---|---|
| libpg-query | PostgreSQL parser (full API on PG 18+, parse-only on 13β17) | 13, 14, 15, 16, 17, 18 | libpg-query |
| @pgsql/parser | Multi-version parser (runtime selection) | 15, 16, 17, 18 | @pgsql/parser |
| @pgsql/types | TypeScript type definitions | 13, 14, 15, 16, 17, 18 | @pgsql/types |
| @pgsql/enums | TypeScript enum definitions | 13, 14, 15, 16, 17, 18 | @pgsql/enums |
Each versioned package uses npm dist-tags for PostgreSQL version selection:
# Install specific PostgreSQL version
npm install libpg-query@pg18 # PostgreSQL 18 (latest)
npm install libpg-query@pg17 # PostgreSQL 17
npm install libpg-query@pg16 # PostgreSQL 16
npm install @pgsql/types@pg18 # Types for PostgreSQL 18
npm install @pgsql/enums@pg15 # Enums for PostgreSQL 15
# Install latest (defaults to pg18)
npm install libpg-query
npm install @pgsql/types
npm install @pgsql/enums
libpg-query (all PG versions)@pgsql/parser (dynamic version selection)@pgsql/types and/or @pgsql/enumslibpg-query@pg18 β the full API ships on PG 18+ (13β17 remain parse-only)For detailed API documentation and usage examples, see the package-specific READMEs:
This package uses a WASM-only build system for true cross-platform compatibility without native compilation dependencies.
Run these commands from inside a versions/* directory (e.g., versions/17):
Install dependencies:
pnpm install
Build WASM artifacts:
pnpm run build
Clean WASM build (if needed):
pnpm run clean
Rebuild WASM artifacts from scratch:
pnpm run clean && pnpm run build
The WASM build process:
wasm/libpg-query.js and wasm/libpg-query.wasm filespnpm run test
pnpm run clean && pnpm run build && pnpm run test
"fetch failed" errors during tests:
pnpm run clean && pnpm run build"WASM module not initialized" errors:
Build environment issues:
.wasm not found
To avoid duplication across PostgreSQL versions, common files are maintained in the templates/ directory:
LICENSE, Makefile, src/index.ts, src/libpg-query.d.ts, src/wasm_wrapper.cTo update version-specific files from templates:
npm run copy:templates
This ensures consistency while allowing version-specific customizations (e.g., patches for version 13).
The build process generates these files:
wasm/libpg-query.js - Emscripten-generated JavaScript loaderwasm/libpg-query.wasm - WebAssembly binarywasm/index.js - ES module exportswasm/index.cjs - CommonJS exports with sync wrappersBuilt on the excellent work of several contributors:
π Built by the Constructive team β creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
pgsql-parser.pgsql-parser for parsing and deparsing SQL queries.AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
TypeScript
73.3%
JavaScript
20.9%
C
3.9%
Makefile
2.0%
This is the official PostgreSQL parser, compiled to WebAssembly (WASM) for seamless, cross-platform compatibility. Use it in Node.js or the browser, on Linux, Windows, or anywhere JavaScript runs.
Built to power pgsql-parser, this library delivers full fidelity with the Postgres C codebase β no rewrites, no shortcuts.
π― Want to parse + deparse (full round trip)?
We highly recommend usingpgsql-parserwhich leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query.
Need to support multiple PostgreSQL versions at runtime?
Use@pgsql/parserfor dynamic version selection β parse SQL with PostgreSQL 15, 16, 17, or 18 in a single package!import { parse } from '@pgsql/parser'; // Parse with specific PostgreSQL version const result15 = await parse('SELECT * FROM users', 15); const result18 = await parse('SELECT * FROM users', 18);
npm install libpg-query
import { parse } from 'libpg-query';
const result = await parse('SELECT * FROM users WHERE active = true');
// {"version":180004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]}
This repository contains multiple packages to support different PostgreSQL versions and use cases:
| Package | Description | PostgreSQL Versions | npm Package |
|---|---|---|---|
| libpg-query | PostgreSQL parser (full API on PG 18+, parse-only on 13β17) | 13, 14, 15, 16, 17, 18 | libpg-query |
| @pgsql/parser | Multi-version parser (runtime selection) | 15, 16, 17, 18 | @pgsql/parser |
| @pgsql/types | TypeScript type definitions | 13, 14, 15, 16, 17, 18 | @pgsql/types |
| @pgsql/enums | TypeScript enum definitions | 13, 14, 15, 16, 17, 18 | @pgsql/enums |
Each versioned package uses npm dist-tags for PostgreSQL version selection:
# Install specific PostgreSQL version
npm install libpg-query@pg18 # PostgreSQL 18 (latest)
npm install libpg-query@pg17 # PostgreSQL 17
npm install libpg-query@pg16 # PostgreSQL 16
npm install @pgsql/types@pg18 # Types for PostgreSQL 18
npm install @pgsql/enums@pg15 # Enums for PostgreSQL 15
# Install latest (defaults to pg18)
npm install libpg-query
npm install @pgsql/types
npm install @pgsql/enums
libpg-query (all PG versions)@pgsql/parser (dynamic version selection)@pgsql/types and/or @pgsql/enumslibpg-query@pg18 β the full API ships on PG 18+ (13β17 remain parse-only)For detailed API documentation and usage examples, see the package-specific READMEs:
This package uses a WASM-only build system for true cross-platform compatibility without native compilation dependencies.
Run these commands from inside a versions/* directory (e.g., versions/17):
Install dependencies:
pnpm install
Build WASM artifacts:
pnpm run build
Clean WASM build (if needed):
pnpm run clean
Rebuild WASM artifacts from scratch:
pnpm run clean && pnpm run build
The WASM build process:
wasm/libpg-query.js and wasm/libpg-query.wasm filespnpm run test
pnpm run clean && pnpm run build && pnpm run test
"fetch failed" errors during tests:
pnpm run clean && pnpm run build"WASM module not initialized" errors:
Build environment issues:
.wasm not found
To avoid duplication across PostgreSQL versions, common files are maintained in the templates/ directory:
LICENSE, Makefile, src/index.ts, src/libpg-query.d.ts, src/wasm_wrapper.cTo update version-specific files from templates:
npm run copy:templates
This ensures consistency while allowing version-specific customizations (e.g., patches for version 13).
The build process generates these files:
wasm/libpg-query.js - Emscripten-generated JavaScript loaderwasm/libpg-query.wasm - WebAssembly binarywasm/index.js - ES module exportswasm/index.cjs - CommonJS exports with sync wrappersBuilt on the excellent work of several contributors:
π Built by the Constructive team β creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
pgsql-parser.pgsql-parser for parsing and deparsing SQL queries.AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
TypeScript
73.3%
JavaScript
20.9%
C
3.9%
Makefile
2.0%