PgSanity is a Python utility that checks the syntax of PostgreSQL SQL files. It operates by leveraging the `ecpg` command-line tool, which is part of the PostgreSQL client development tools. This allows `pgsanity` to use the exact same parser as PostgreSQL to identify SQL syntax errors, making it a reliable tool for quality assurance and testing of SQL scripts. The current version is 0.3.0, and it maintains a regular release cadence.
pip install pgsanityNo compatibility data collected yet for this library.
PgSanity is primarily a command-line tool. The quickstart demonstrates how to install it and then use the `pgsanity` command to check SQL syntax from a file or directly from standard input. A successful check returns an exit code of 0, while errors result in a non-zero exit code and error messages on stderr.
Install the PostgreSQL client development tools for your operating system (e.g., `postgresql-client-dev` on Debian/Ubuntu, `postgresql-devel` on RHEL/CentOS, or the full PostgreSQL installer on Windows/macOS) and ensure `ecpg` is in your system's PATH.
Interact with `pgsanity` by executing it as a separate process (e.g., using Python's `subprocess` module) rather than attempting to import and call functions directly from the `pgsanity` package.
Install the PostgreSQL client development tools for your operating system. For Debian/Ubuntu, use `sudo apt-get install libecpg-dev`. For RHEL/CentOS, use `sudo yum install postgresql-devel` or `dnf install postgresql12-devel`. After installation, ensure `ecpg` is accessible in your system's PATH.
Interact with `pgsanity` by executing it as a separate process (e.g., using Python's `subprocess` module) rather than attempting to import and call functions directly from the package. Alternatively, run `pgsanity` directly from the shell.
Carefully review the SQL syntax in your file around the reported line number and the token in question. Be aware that `ecpg`'s error reporting can sometimes point to a location slightly after the actual fault (e.g., a missing semicolon in a preceding statement might cause an error on the next statement).