Fix regex in extract_sql
to correctly handle SQL containing CTEs (without matching WITHIN)
#512
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description:
This pull request addresses an issue in the
extract_sql
function where the regex used to extract SQL queries from LLM responses incorrectly matches the keyword "WITHIN". This results in incomplete and invalid SQL queries being extracted. The regex has been updated to use word boundaries to ensure accurate matching of the "WITH" keyword at the start of CTEs. This fix resolves the syntax errors encountered when running the extracted SQL queries.Related Previous Pull Requests:
Issue:
When a response contains a SQL query with the keyword "WITHIN", the regex mistakenly captures partial SQL statements, resulting in invalid SQL. An example of such an SQL query is provided below:
Example SQL:
Extracted SQL before fix:
Solution:
The regex was updated to use word boundaries to correctly match the keyword "WITH" at the start of a CTE, ensuring accurate extraction of SQL statements.
Updated regex:
The current fix ensures that SQL extraction handles CTEs properly without misinterpreting "WITHIN" as a CTE starter.