Hi everyone,
I’m developing a plugin for DataGrip called cteXecutor
. Its goal is to analyze SQL statements with multiple CTEs and allow executing a selected CTE (along with its dependencies), even if the CTE is not the final one in the chain.
Right now, my execution flow looks like this:
- Analyze the SQL and identify relevant CTE fragments.
- Combine them into a full
WITH ... SELECT
string. - Insert that SQL string temporarily at the end of the document.
- Select the inserted range, execute it using the default execute action.
- Remove the inserted text and restore the cursor position.
This works, but it feels hacky.
My question:
- Is there a way to execute non-contiguous SQL fragments directly? (i.e. select multiple ranges in the editor and execute them as one block?)
- Alternatively, is there a JetBrains API that lets me execute a raw SQL string (not part of the editor), ideally within the current database context?
The tricky part here might be variable bindings or query parameters, which are normally handled through the editor.
Any advice or pointers would be appreciated!
Thanks!