pgcat icon indicating copy to clipboard operation
pgcat copied to clipboard

Switch query parser to `pg_query.rs`

Open mdashti opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. Currently, pgcat is using sqlparser-rs to parse user queries. That's taken us to where we are today, which is great. However, sqlparser-rs does not correctly parse all PostgreSQL queries. There are already some open PRs to fix the known issues (e.g., https://github.com/sqlparser-rs/sqlparser-rs/pull/1000 and https://github.com/sqlparser-rs/sqlparser-rs/pull/1002), but it's not going to be 100% PG compatible.

Describe the solution you'd like The closest to PostgreSQL parser that we can get is to use the PostgreSQL parser itself :)

Here's the maintained (extracted) C library: libpg_query, and here's its port to Rust (by pganalyze): pg_query.rs

I wanted to ask for everyone's opinion (especially the main pgcat maintainers) about changing our SQL parser from sqlparser-rs to pg_query.rs. If I see enough support for this change, I can put-together a PR for it.

mdashti avatar Oct 13 '23 23:10 mdashti

I believe not only pg_query.rs is the most correct Postgres SQL parser but also it's faster than sqlparser. There is a draft PR by another contributor with that integration: https://github.com/postgresml/pgcat/pull/525

levkk avatar Oct 13 '23 23:10 levkk

Thanks for the reference to PR #525. Cool stuff!

However, that PR only uses pg_query.rs without removing the current usages of sqlparser. I'll create a PR for that.

mdashti avatar Oct 14 '23 00:10 mdashti

Just curious about any progress for this ?

KennyChenFight avatar Jan 01 '24 06:01 KennyChenFight