r/learnSQL • u/Commercial-Can-9371 • 1d ago
Is there any point proofreading SQL an agent wrote?
My manager has started pasting Claude-written SQL into Slack with "can you check this is right?". They always look fine on the page. Last week's joined to dim_customer_v2, which still exists but stopped updating in March. The one before used a revenue column that includes tax because it's the one with the obvious name. Both read perfectly well, both answers were wrong, and I only caught them because I happen to know the history of those tables. I mean, our BI tool's chat shows the SQL behind every chart now too, and I don't see how reading it would have caught either of those. Right now the only real check is whoever happens to remember the history of the tables.
3
u/reditandfirgetit 1d ago
Yes. It's not to the point you should trust its output. Often inefficient or, as you've identified, wrong tables
1
u/BigMikeInAustin 1d ago
Doesn't matter where the code is from. Gotta check it. A human could easily have written the same thing, where it is logically correct, but real world data is nit accounted for.
1
u/_Royalty_ 1d ago
Auditing the output and understanding the data is part of being an analyst. If your dashboards aren't showing orders for the last 3 months, you should be able to identify that as an issue. Always check the source. Then check it again.
1
u/alinroc 1d ago
Yes, you still need human reviewers in the loop. Not just for historical knowledge but also because these things can create overly-complex, poor-performing queries that seem "good enough."
But also:
The problem you uncovered could have happened just as easily with a new (human) member of the team/organization who doesn't have this historical context for your system. Congratulations - you're now a single point of failure or, if you've read The Phoenix Project, you're Brent because you're the only person (apparently) who knows about this history.
If you're going to continue to rely upon Claude to generate your queries, "the history of the tables" is critical context that should be baked into your prompts, skills,
CLAUDE.md, or whatever. The same way you'd educate a new team member during onboarding.1
u/Discordbothost 1d ago
For the tax example, I'd keep one known order in the query test. If it's $100 plus $20 tax and the metric is revenue before tax, assert that the query returns $100 for that order. Now the wrong column fails even when the SQL looks fine.
1
u/henry_barnes_745 13h ago
why is dim_customer_v2 still queryable if it stopped loading in march? we revoke select on anything that hasn't loaded in 30 days and wait to see who complains
1
u/henry_barnes_745 13h ago
why is dim_customer_v2 still queryable if it stopped loading in march? we revoke select on anything that hasn't loaded in 30 days and wait to see who complains
1
u/SessionIndependent17 3h ago
Because it's your ass on the line if it did something wrong
1
u/JohnCasey3306 3h ago
Hell yes. Oof.