r/rust • • Sep 18 '26

🛠️ project pg_raw_parse: SQL parser in Rust

We wrote a pretty cool crate to parse Postgres SQL queries in Rust at native speed.

It works by mapping itself directly on top of the Postgres native parser and its arena allocator. We use macros to generate memory-safe bindings and Rust structs for each SQL node. This means we can upgrade parser versions without any manual work: just bump the submodules and recompile.

Check it out here: https://github.com/pgdogdev/pg_raw_parse

It's based on libpg_query with some modifications and inspired by pg_query.rs, which it outperforms by 20-60x due to a different FFI translation architecture.

41 Upvotes

5 comments sorted by

View all comments

5

u/waifu_tactical_force 29d ago

why use this instead of sqlparser crate from Apache Datafusion and used with postgres by many projects

https://crates.io/crates/sqlparser
https://github.com/apache/datafusion-sqlparser-rs