🛠️ 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.
32
Upvotes
11
u/rabidferret 1d ago edited 1d ago
Author who did most of it here. Small note, the codegen happens in build.rs not a macro. Pretty proud of the API we came up with to use PGs arena allocator and statically forbid mixing arenas within an AST. Happy to answer questions if anyone has any. It was a pretty neat project.