Expand description

Rust pg_query   Build Status Latest Version Docs Badge

PostgreSQL parser that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.

Warning! This library is in early stages of development so any APIs exposed are subject to change.

Getting started

Add the following to your Cargo.toml

[dependencies]
pg_query = "0.1"

Example: Parsing a query

use pg_query::{Node, NodeEnum, NodeRef};

let result = pg_query::parse("SELECT * FROM contacts");
assert!(result.is_ok());
let result = result.unwrap();
assert_eq!(result.tables(), vec!["contacts"]);
assert!(matches!(result.protobuf.nodes()[0].0, NodeRef::SelectStmt(_)));

Re-exports

pub use protobuf::node::Node as NodeEnum;
pub use protobuf::Node;

Modules

Structs

Represents the resulting fingerprint containing both the raw integer form as well as the corresponding 16 character hex value.

Enums

Error structure representing the basic error scenarios for pg_query.

Functions

Converts a parsed tree back into a string.

Fingerprints the given SQL statement. Useful for comparing parse trees across different implementations of libpg_query.

Normalizes the given SQL statement, returning a parametized version.

Parses the given SQL statement into the given abstract syntax tree.

An experimental API which parses a PLPGSQL function. This currently returns the raw JSON structure.

Scan a sql query into a its component of tokens.

Split a well-formed query into separate statements.

Split a potentially-malformed query into separate statements. Note that invalid tokens will be skipped

Type Definitions

Convenient Result alias for returning pg_query::Error.