At the lower level the module exposes several libpg_query functions:

  1. pglast.parser.parse_sql_json()

  2. pglast.parser.parse_sql_protobuf()

  3. pglast.parser.parse_plpgsql_json()

  4. pglast.parser.fingerprint()

  5. pglast.parser.scan()

  6. pglast.parser.split()

  7. pglast.parser.deparse_protobuf()

The first two take an SQL statement and return the correspondent parse tree respectively as a JSON encoded value and a Protobuf encoded value; the third function takes a PLpgSQL statement and returns the parse tree as JSON, the fourth returns an hash of the given statement that can be used to compare different SQLs, the fifth returns a sequence of tokens that compose a SQL statement, the sixth returns a sequence of the single statements and the last one accepts a Protobuf-serialized statement and reproduce the original SQL statement.

One more function, pglast.parser.parse_sql(), is similar to parse_sql_json() but instead of JSON returns the syntax tree represented by a hierarchy of instances of the classes implemented in the pglast.ast module.

On top of that, the module implements two serializations, one that transforms a Node into a raw textual representation and another that returns a prettified < representation. The latter is exposed by the pgpp CLI tool, see the Command line section of the examples of usage.