skillfed

pgsanity

Check syntax of sql for PostgreSQL

pgsanity v0.3.0 537.5K downloads/30d#6,119 on PyPI325
Permissive license MIT AGING released

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

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

pgsanity on PyPI

pip

pip install pgsanity

uv

uv add pgsanity

poetry

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 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)

Evidence: pgsanity-0.3.0-py3-none-any.whl

Keywords: pgsanity, sql, syntax, postgresql, postgres

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

Tags

postgresql sql syntax checkersql linter postgresvalidate sql filespostgres sql validationpre-commit sql lintingecpg syntax checkersql error detection
sql-lintingpostgresci-cd

More Utilities packages