API documentation¶
This chapter briefly explains some implementation detail.
-
exception
pglast.
Error
¶ Top level error exception.
Package’s author.
-
pglast.
__version__
= 'v3.8'¶ Package’s version.
-
pglast.
prettify
(statement, safety_belt=False, preserve_comments=False, **options)¶ Render given statement into a prettified format.
- Parameters
statement (str) – the SQL statement(s)
safety_belt (bool) – whether to perform a safe check against bugs in pglast’s serialization
preserve_comments (bool) – whether comments shall be preserved, defaults to not
**options – any keyword option accepted by
IndentedStream
constructor
- Returns
a string with the equivalent prettified statement(s)
When safety_belt is
True
, the resulting statement is parsed again and its AST compared with the original statement: if they don’t match, a warning is emitted and the original statement is returned. By default it isFalse
, so no double check is done.
-
pglast.
split
()¶ Split the given stmts string into a sequence of the single
SQL
statements.By default this uses the parser to perform the job; when with_parser is
False
the scanner variant is used, indicated when the statements may contain parse errors.When only_slices is
True
, return a sequence ofslice
instances, one for each statement, instead of statements text.NB: leading and trailing whitespace are removed from the statements.
Packages
pglast.parser
— The interface with libpg_querypglast.ast
— Python classes representing PG parser nodespglast.enums
— Enumerated constantspglast.keywords
— Various kinds of PostgreSQL keywordspglast.node
— The higher level interface to the parse treepglast.stream
— The serialization machinerypglast.printers
— Specialized printer functionspglast.printers.sfuncs
— Special function printerspglast.visitors
— Other ways to inspect and manipulate the AST