DEV Community

Lay Patel
Lay Patel

Posted on

SQL Doctor: An Offline Tutor That Explains PostgreSQL Errors to My DBMS Lab Classmates

Hacktoberfest Weekend Challenge: Build for a Friend Submission 🤝

This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend

What I Built

This semester I'm taking a DBMS lab where we write PostgreSQL queries every week. Writing the queries isn't the hard part. Understanding the errors is.

column "instructor.name" must appear in the GROUP BY clause or be used in an aggregate function makes perfect sense once you know SQL. A few weeks into your first database course, it reads like a riddle. So I built something for my friend Jay Patel and my lab classmates.

SQL Doctor is a small web app. You paste the query that failed and the error PostgreSQL printed, and it tells you:

  • What went wrong, in one or two plain sentences
  • Where, quoting the exact part of the query that broke
  • The fixed query, changing only what's needed
  • A tip so the same mistake doesn't happen again

It can explain in English, Hinglish or Gujarati, because that's how my classmates and I actually talk. You can also paste your CREATE TABLE statements for more accurate answers, and there are four built-in examples of the mistakes we make most often.

Demo

Try the interface at sql-doctor.onrender.com. The hosted copy is a preview of the interface. The real answers come from Gemma running locally on your own laptop, which is the whole point, so clone the repo below to run it yourself.

Code

SQL Doctor

Paste a PostgreSQL query that failed and the error it gave you. SQL Doctor explains what went wrong in plain words, points to the exact part of the query that broke, and shows the fixed query. It can explain in English, Hinglish or Gujarati.

I built it for my DBMS lab classmates, who lose a lot of lab time staring at errors like column "x" must appear in the GROUP BY clause.

It runs entirely on your own laptop with Gemma 4, an open-weight model, through Ollama. Your queries never leave your machine, it works without internet, and it costs nothing to run.

Run it

  1. Install Ollama and download the model:

    ollama pull gemma4:e4b
    Enter fullscreen mode Exit fullscreen mode

    On a slower laptop, use gemma4:e2b instead and change the model name in the app's sidebar.

  2. Install the Python packages:

    python -m venv .venv
    source .venv/bin/activate      # Windows: .venv\Scripts\activate
    pip install
    …
    Enter fullscreen mode Exit fullscreen mode

How I Built It

SQL Doctor runs entirely on the laptop:

  • Gemma 4 (gemma4:e4b) does the explaining. It's an open-weight model small enough to run on an 8 GB laptop.
  • Ollama serves the model locally.
  • Streamlit is the interface, about 300 lines of Python in a single file.

Most of the thinking went into the system prompt. It forces every answer into the same four sections, so answers are consistent and easy to skim. It runs at a low temperature so the fixes stay steady. And it has two rules I care about most: never invent tables or columns the student didn't mention, and say "I'm not sure" instead of guessing. A tutor that confidently gives you a wrong fix is worse than no tutor.

The answer streams in as Gemma writes it. Once it's done, the sections turn into small badges: red for what broke, green for the fix. The design reuses the theme from Netra, another project of mine: neutral greys everywhere, blue only for things you can click, and color only where it carries meaning.

Why Does Open Innovation Matter?

For a student tool, open models are the whole point.

  • It's free. None of my classmates is going to put a credit card on an API account to debug a lab query. Gemma runs locally at zero cost per question.
  • It works offline. Once the model is downloaded, it doesn't need the internet at all.
  • Our work stays on our laptops. Lab assignments never get sent to someone else's server.
  • It fits the hardware. If a friend's laptop is older, they can switch to gemma4:e2b in the settings.

A closed API would have meant keys, usage limits and a bill, and I couldn't hand it to a friend without handing over my key too. With Gemma and Ollama, sharing it is just git clone.

What Jay Said

I showed SQL Doctor to Jay, and his reply was one word: "Crazzy! 🔥"

My Agent Session

I built this with help from Claude, which helped me scaffold the Streamlit app, shape the system prompt and restyle it with my Netra theme. I then tested it on errors from my own lab work.

Prize Categories

Best Use of Gemma: SQL Doctor runs on Gemma 4 locally through Ollama, and Gemma does all of the explaining.

Top comments (0)