Is it possible to split apart multi-statement queries?
Hi there, thanks for the library!
I was wondering if there was a way to split a multi-statement query into individual statements.
For example, given an SQL query like select 1; select 2 — a way to deparse the individual parts back into select 1 and select 2?
My use case is that my application has an event listener that can intercept queries and run explain analyze … on them. I want that to be able to support multi-statement queries.
Thanks for reaching out!
The C library has the split functions for this, which we haven't yet made available in the Ruby bindings. This should be fairly straightforward to do, you'd just have to expand the Ruby-specific C code in pg_query_ruby.c.
Are you interested in making a PR for this?
I'll see if I can make headway on that. Thanks for the pointer :)
This has been added in 0077294d926403bc8291298dd8ddaf2f3695d45f, which can be accessed through PgQuery.split_with_parser(query)