SQL Drafts and Query Reviews From the Terminal
Two model candidates for the same SQL workflow
SQL generation looks easy until a plausible query quietly doubles revenue. When I pick a model for database work, I care less about polished explanations than whether it preserves grain, handles NULL correctly, and asks about missing business rules.
My starting comparison would be DeepSeek V4 Flash for routine drafting and Claude Sonnet 5.5 for deeper review. Those are proposed roles, not benchmark results: model names alone do not establish SQL accuracy, latency, or cost. The useful comparison happens against your schema, dialect, and representative mistakes.
Fluxo makes that experiment straightforward: one key and one base URL, https://api.fluxorelay.com, cover Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok and more. Keep the prompt and fixtures fixed while changing the model.
Give both candidates the same PostgreSQL contract
Start with a small, realistic task: calculate monthly paid revenue by customer segment. Supply the relevant table definitions, foreign keys, indexes, PostgreSQL version, and business definitions. Specify whether revenue includes refunds, whether timestamps use UTC, and whether customers without payments belong in the output.
My prompt contract is simple: produce one read-only query, list assumptions, identify possible duplicate-producing joins, and suggest checks. If a necessary definition is missing, ask before generating SQL. Request an explanation of the result grain, not a lengthy internal reasoning transcript.
- Include table cardinalities and representative rows, with sensitive values removed.
- Define whether each output row represents customers, invoices, or months.
- Provide expected results for fixtures containing refunds and duplicate joins.
- Keep credentials and production access outside the model interaction entirely.
SQL drafting: speed only counts after correctness
For drafting, compare both candidates on the identical request. DeepSeek V4 Flash is my first candidate for the quick iteration lane; Claude Sonnet 5.5 is the alternative to test against it. Neither gets credit merely for returning valid syntax.
- DeepSeek V4 Flash must pass the same fixtures before earning routine drafting work.
- Claude Sonnet 5.5 must justify additional measured cost or latency through better outcomes.
Check a one-to-many join explicitly. If invoices join invoice_items and payments directly, both child tables can multiply rows. A correct response should aggregate each child to the required grain before joining, or otherwise demonstrate why multiplication cannot occur.
Also test half-open timestamp ranges, empty groups, and NULL behavior. Compare outputs against hand-checked fixtures, not another model’s answer. Record correctness, clarification quality, wall-clock latency, token usage, and actual billed cost. A fast wrong query is not a bargain.
Query review: reward discoveries, not confident prose
For review, give both models an existing query with deliberately planted defects. Include a LEFT JOIN accidentally converted into an inner join by a WHERE predicate, a nullable NOT IN subquery, and a revenue total inflated by join fan-out. Keep the expected defects hidden from the prompt.
- DeepSeek V4 Flash should identify concrete defects without inventing schema constraints.
- Claude Sonnet 5.5 should connect each finding to a reproducible failure case.
Score true findings, missed defects, and false alarms separately. Ask for a minimal correction and a test that fails before the correction. Reject performance certainty without evidence: an index recommendation is a hypothesis until the plan and workload support it.
Use EXPLAIN first. EXPLAIN ANALYZE executes the statement, so reserve it for controlled environments with appropriate permissions and timeouts. Never let an automated review silently execute a generated mutation.
The verdict: separate SQL drafting from high-risk review
My verdict is to start with DeepSeek V4 Flash for fixture-backed drafts and evaluate Claude Sonnet 5.5 as the reviewer for consequential queries. Promote either only on local results. If one model wins both lanes, simplify; two models are not inherently safer.
Fluxo works with Claude Code, Codex, Gemini CLI, and any OpenAI SDK. Billing follows real tokens, including cache reads and writes, with no monthly fee, so include those charges in comparisons. If you want to run this evaluation, consider creating a Fluxo account. Users also earn a referral share when people they invite pay; keep that separate from technical scoring.