A Python 3 module that exposes the parse tree of a PostgreSQL statement (extracted by the almost standard PG parser repackaged as a standalone static library by libpg_query) as a set of interconnected nodes, usually called an abstract syntax tree. It provides functionalities for parsing SQL, generating ASTs, and prettifying SQL statements. The library is actively maintained with frequent releases, currently at version 7.13, and targets PostgreSQL 17.
pip install pglastVerified import paths — ran on the pinned version, not inferred.
Parses an SQL statement into an Abstract Syntax Tree (AST) and then demonstrates how to traverse the AST for basic inspection, followed by prettifying the original SQL statement.
Update code to directly interact with `pglast.ast` objects. Remove any JSON parsing logic after calling `parse_sql()`.
Replace usages of `pglast.node` wrappers with direct interaction with `pglast.ast` classes.
Adjust import paths and function calls to use `pglast.printers` and `pglast.stream` as appropriate.
Ensure that code handling `Float` node values expects a string and performs explicit conversion if numerical operations are required.
Upgrade Python environment to 3.9 or higher. Be aware of potential syntax changes or new features in PostgreSQL 17 that might affect parsing or prettification if interacting with older database versions.
For complex PL/pgSQL, be aware that the internal body might not be fully parsed into a detailed AST. You might need to extract the function body as a string and process it with external tools or custom logic.
Correct the SQL query to be valid PostgreSQL syntax. For example, `parse_sql('select 1 from; select 2')` is invalid, but `parse_sql('select 1; select 2')` would be correct if using the `split` function, or `parse_sql('select 1')` for a single statement.Try installing `pglast` from source instead of using a pre-built wheel. This can often be done by first uninstalling any existing `pglast` installation (`pip uninstall pglast`) and then reinstalling (`pip install --no-binary :all: pglast`) to force a source build, ensuring all necessary build tools (like Xcode Command Line Tools on macOS) are installed.
Upgrade `pglast` to its latest version (e.g., `pip install --upgrade pglast`) which may include a fix for this import issue. If the problem persists, consider using a different compatible Python version.
Ensure that essential development tools are installed on your system. On Debian/Ubuntu, run `sudo apt-get install build-essential`. On macOS, install Xcode Command Line Tools using `xcode-select --install`. For Windows, ensure a C++ build environment (like MSVC from Visual Studio Build Tools) is properly configured.
No dependency data recorded yet.