Lesson 1691 of 2116
AI coding: SQL by explanation-first, query-second
Make the AI explain in English what the query will do before writing it. Reading the plan in your head catches the join mistakes.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The premise
- 2SQL generation
- 3query planning
- 4verifiable output
Concept cluster
Terms to connect while reading
Section 1
The premise
AI-generated SQL frequently joins the wrong way or aggregates over the wrong grain. Forcing an English explanation first lets you catch the misunderstanding before running the query against production.
What AI does well here
- Translate English questions into syntactically valid SQL
- Use window functions and CTEs when prompted
- Suggest indexes for slow queries when given the plan
What AI cannot do
- Know your schema's actual cardinality and skew
- Catch silent fan-out from a wrong join
- Decide acceptable query cost on your warehouse
Key terms in this lesson
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “AI coding: SQL by explanation-first, query-second”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Creators · 40 min
Agents vs. Autocomplete — the Mental Model Shift
Autocomplete is a suggestion. An agent is an actor. The mental model you bring to each is different, and conflating them is the number-one reason teams trip over AI coding.
Creators · 50 min
Test-Driven AI Development
TDD was already the gold standard. Paired with an agent, it becomes the tightest feedback loop in software. Here's the full workflow and the pitfalls.
Creators · 50 min
Vector DB Basics With pgvector
Store embeddings, search by similarity. The foundation of every RAG system. Postgres plus pgvector gets you there.
