pgsanity
Check syntax of sql for PostgreSQL
Decision gist · record as of 2026-08-14
Yes, if you need PostgreSQL SQL syntax validation in CI/CD or pre-commit workflows and have ecpg available on your system. The package is lightweight, permissively licensed, and well-integrated with Unix tooling. The aging maintenance status is not a blocker for a stable, narrow-purpose tool, but verify that ecpg is available in your deployment environment before committing to it.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- ecpg must be installed on your system (Ubuntu/Debian: libecpg-dev, RHEL/CentOS: postgresql-devel, Arch: postgresql-libs).
- Python >= 3.9 required.
- Low friction: pure Python wheel with no runtime dependencies.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution with minimal obligations, making it safe for commercial and proprietary projects.
last release 2025-09-20 (328 days) · last repo commit 2025-09-20 · 325 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 537,526 downloads/mo, #6,119 on PyPI
Alternatives
Verify before relying
pip install pgsanity
pgsanity file_with_sql.sql
echo "select mycol from mytable;" | pgsanity- Whether ecpg availability varies significantly across operating systems beyond the documented package managers
- How error line reporting accuracy compares to other PostgreSQL syntax validators
- Whether the package handles all PostgreSQL dialect variants or only a subset
What it is and what it does
PgSanity is a command-line tool and Python package that checks PostgreSQL SQL files for syntax errors. It works by converting SQL into a C file with embedded SQL, then running it through the ecpg preprocessor—the same parser PostgreSQL uses internally—to catch syntax problems before deployment. The tool accepts filenames as arguments, reads from stdin if none are provided, and exits with status 0 for valid SQL or 1 when errors are found.
The package requires ecpg (part of PostgreSQL development libraries) to be installed on your system, plus Python 3.9 or later. It integrates well with Unix pipelines and find/xargs workflows, and can be used as a pre-commit hook for automated validation in version control. Error messages come directly from ecpg and include line numbers, though the reported line may point to the statement after the actual error.
Use it for
- Validate SQL files in CI/CD pipelines before deployment to catch syntax errors early
- Use as a pre-commit hook to prevent malformed SQL from being committed to version control
- Batch-check multiple SQL files with find and xargs to audit a codebase for syntax problems
- Integrate into development workflows to catch typos and dialect mismatches interactively via stdin
- Enforce SQL standards in teams by running validation on all .sql files in a repository
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need PostgreSQL SQL syntax validation in CI/CD or pre-commit workflows and have ecpg available on your system.
The package is lightweight, permissively licensed, and well-integrated with Unix tooling. The aging maintenance status is not a blocker for a stable, narrow-purpose tool, but verify that ecpg is available in your deployment environment before committing to it.
Install
pgsanity on PyPI
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is aging—last release was 328 days ago—but the repository remains active with recent commits and no archived status.
ecpg must be installed on your system (Ubuntu/Debian: libecpg-dev, RHEL/CentOS: postgresql-devel, Arch: postgresql-libs). Python >= 3.9 required.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal obligations, making it safe for commercial and proprietary projects.
Quickstart
pip install pgsanity
pgsanity file_with_sql.sql
echo "select mycol from mytable;" | pgsanity
Verify before relying
- Whether ecpg availability varies significantly across operating systems beyond the documented package managers
- How error line reporting accuracy compares to other PostgreSQL syntax validators
- Whether the package handles all PostgreSQL dialect variants or only a subset
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Aging 328 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 537,526 / month, #6,119 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: POSIXProgramming Language :: Python :: 3Topic :: DatabaseTopic :: Database :: Database Engines/ServersTopic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Utilities |
Evidence: pgsanity-0.3.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “postgresql sql syntax checker”
- pgsanityPgSanity validates PostgreSQL SQL syntax by wrapping the ecpg parser,…
- squawk-cliLinter that analyzes PostgreSQL migrations and SQL statements to…
- pglastParses PostgreSQL SQL statements into an abstract syntax tree and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Utilities packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Detects and normalizes text encoding from unknown or ambiguous sources, supporting all IANA character sets that Python's core library provides codecs for, with the ability to register custom codecs.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Pygments is a syntax highlighter that colorizes source code and text in over 500 languages and formats, outputting to HTML, LaTeX, RTF, SVG, images, or ANSI terminal sequences.
Install it if you need to display or transform source code.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
See also buildpg · pglast · sql-formatter · pytest-pgsql · squawk-cli · pgspecial · pgcli · pgdb · testing.postgresql · pipestat