AI error fix in place

functional

When AI explains a failed statement, replace the broken statement with its fix in one undoable edit.

When a query fails, Explain Last Error (AI) in the command palette opens the AI drawer seeded with the error, the statement that failed, and the script it ran in. The prompt asks for only the corrected failing statement back. When the answer includes corrected SQL, you do not have to copy it back by hand: next to Insert and New query the answer offers Replace failing statement.

What gets replaced

SQLly finds the statement that failed - not just wherever the caret happens to be - and swaps it for the AI's version. The conversation remembers which tab and which run the error came from when you started it, so a later failure in another tab, or a successful run elsewhere, does not change where the fix goes. It locates the run in that tab (the recorded run region, or the run's text if you have edited above it since), then narrows to the one failing statement using the position the engine reported: the line number for SQL Server and MySQL (respecting GO batches), the character position for PostgreSQL. A comment directly above the statement stays where it is. The new text is selected so you can see exactly what changed.

If the answer repeats the rest of the script anyway, pasting it over one statement would duplicate everything around it, so SQLly replaces the whole run instead and says so in the status bar. The button appears on the answers to the error question only: asking a follow-up, starting a new chat, or applying the fix once turns it off.

  1. Run a script; one statement fails.
  2. Choose Explain Last Error (AI).
  3. Read the explanation, then click Replace failing statement on the fixed SQL.
  4. Run again. If the fix is wrong, Cmd/Ctrl+Z brings the original statement back in one step.
SQLly
An AI error explanation with the Replace failing statement button, and the corrected statement selected in the editor.
An AI error explanation with the Replace failing statement button, and the corrected statement selected in the editor.
It never guesses. If the statement can no longer be found honestly - its text changed since the error, or the engine reported no position - SQLly inserts the fix at the caret of the tab that failed instead and says why in the status bar. If that tab was closed, or it has run again since the error, nothing is changed: the status bar says why, and Insert still puts the SQL into the current editor. The replacement is one undoable edit.