FormatMistakeExample formats a MistakePattern into a human-readable multi-line block suitable for displaying in error messages, documentation, or interactive tutorials. The output includes the mistake name, the wrong SQL snippet, the corrected SQL snippet, and an explanation. Example output: Comm
(mistake MistakePattern)
| 443 | // Right: SELECT dept, COUNT(*) FROM employees GROUP BY dept |
| 444 | // Explanation: Non-aggregated columns in SELECT must appear in GROUP BY |
| 445 | func FormatMistakeExample(mistake MistakePattern) string { |
| 446 | var sb strings.Builder |
| 447 | sb.WriteString(fmt.Sprintf("Common Mistake: %s\n", mistake.Name)) |
| 448 | sb.WriteString(fmt.Sprintf(" ❌ Wrong: %s\n", mistake.Example)) |
| 449 | sb.WriteString(fmt.Sprintf(" ✓ Right: %s\n", mistake.Correct)) |
| 450 | sb.WriteString(fmt.Sprintf(" Explanation: %s\n", mistake.Explanation)) |
| 451 | return sb.String() |
| 452 | } |
| 453 | |
| 454 | // SuggestForWindowFunction provides targeted suggestions for window function syntax |
| 455 | // errors. It inspects the SQL context to detect common mistakes such as a missing |