One possibility for why the parser is failing is I think your posted SQL is invalid: unless I'm reading it wrong, you have 7 parameters to insert but 8 terms because you have a repeated comma. I also note no nested queries in the query provided, so it's also possible that I can't diagnose the issue because you haven't posted the correct target.
If this is an internal utility, you could accomplish your goal with something like
m/insert\s+into\s+(\S+)\s*\(\s*([^)]+?)\s*\)\s*
(?:values\s*\(\s*([^)]+?)\s*\)
|
select\s*(.+?)\s+(?:where|order)
)
/ix
but this has a number of potential issues: nested queries will parse incorrectly, it fails to consider quoted names and string literals, ... Which is why I usually suggest canned code.
Update: Or misparse by me; the regular expression should read
m/insert\s+into\s+(\S+)\s*\(\s*([^)]+?)\s*\)\s*
(?:values\s*\(\s*([^)]+?)\s*\)
|
select\s*(.+?)\s+(?:from\b)
)
/ix
Of course, your posted SQL doesn't actually correspond to the SQL posted in the original_string field in Re^2: Parse complex SQL statement.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|