--- id: pgsanity version: "0.3.0" license: MIT license_treatment: permissive maintenance: aging --- # pgsanity — Check syntax of sql for PostgreSQL License: permissive · Maintenance: aging · Downloads: 537.5K/mo ## 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 above — verify before relying. PgSanity validates PostgreSQL SQL syntax by wrapping the ecpg parser, reporting syntax errors with line numbers and exit codes suitable for CI/CD and pre-commit hooks. 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 pip install pgsanity uv add pgsanity poetry add pgsanity ## Installing pgsanity 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. 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 ecpg must be installed on your system (Ubuntu/Debian: libecpg-dev, RHEL/CentOS: postgresql-devel, Arch: postgresql-libs). Python >= 3.9 required. 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_current - Install friction: low - Maintenance: aging - Downloads: 537.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags postgresql sql syntax checker, sql linter postgres, validate sql files, postgres sql validation, pre-commit sql linting, ecpg syntax checker, sql error detection, sql-linting, postgres, ci-cd [View on SkillFed](https://skillfed.io/packages/pgsanity) · [View on PyPI](https://pypi.org/project/pgsanity/)