Claude Code for SQL analysis: DuckDB, data plugin, checks
Query CSV with DuckDB, draft SQL via Anthropic's data plugin, then validate totals before you share.
Published here , updated · 8 sources · Resume reading
SQL analysis with Claude Code needs validation before any chart leaves the notebook. Use Anthropic's data plugin for exploration and SQL drafts, run DuckDB on the CSV grain you pinned, then share only after /validate totals match that exact grain. [3] [1]
After this page you can pin the grain, query CSV with DuckDB, shape Postgres SQL, fall back to pandas when needed, and fail a share when totals drift. Related: Choose five tools for spreadsheet data, Claude Code for finance. Browse the Claude Code topic.
Install the data plugin, then pin the grain
claude plugin marketplace add anthropics/knowledge-work-plugins
claude plugin install data@knowledge-work-pluginsCommands include /analyze, /explore-data, /write-query, /create-viz, /build-dashboard, and /validate. Without a warehouse MCP, paste results or drop CSV/Excel in the working folder. [3]
/explore-data orders_2026_11.csv
/write-query cohort retention by signup month, DuckDB dialect
/validate before sharing the revenue trend noteTell Claude the grain (order, invoice day, user) and the checksum column up front. Best practices: name what "correct" looks like so Claude can check its own work. [6]
Query local CSV with DuckDB first
DuckDB's quickstart shows arithmetic in SQL, reading CSV via read_csv, grouping revenue, and materializing a table. The CSV overview also allows SELECT * FROM 'flights.csv' and typed read_csv with header and columns. [1] [2]
SELECT product, sum(quantity * price) AS revenue
FROM read_csv('sales.csv')
GROUP BY product
ORDER BY revenue DESC;CREATE TABLE sales AS SELECT * FROM read_csv('sales.csv');You should see the same row count as wc -l (minus the header) before you trust a total. Typed read_csv with header and columns is in the CSV overview when auto-detect is wrong. [1] [2]
Use Postgres SQL shape when the warehouse is relational
PostgreSQL's tutorial shows SELECT with column lists, expressions, WHERE, and ORDER BY. Ask /write-query for your dialect, then run the statement in psql or your warehouse console against a read replica. [3] [4]
SELECT city, (temp_hi + temp_lo) / 2 AS temp_avg, date
FROM weather
WHERE city = 'San Francisco' AND prcp > 0.0
ORDER BY date;Never paste production write credentials into the session. Prefer a read-only role or a CSV export. [6]
Fall back to pandas for in-process frames
pandas' short guide starts with Series and DataFrame construction. Use it when Claude already generated Python and the file fits memory; keep the final checksum in SQL or a plain sum assert you can re-run. [5]
import pandas as pd
df = pd.read_csv("sales.csv")
assert len(df) == 12345 # replace with export row count
print(df.groupby("product")["revenue"].sum())Warning: floating money in pandas still needs Decimal or integer cents before board packs. For that path, continue on Claude Code for finance. [8]
Validate before anyone else sees the chart
/explore-datanotes null rates and odd enums. [3]- DuckDB (or warehouse) query returns row count and sum checksums. [1] [2]
/validatereviews methodology and bias flags before share. [3]- Person signs the note; agent does not email stakeholders alone. [6]
For sheet-native tooling, use Choose five tools for spreadsheet data. [7]
When the data sits in Amazon Redshift, set up the DuckDB Redshift extension and join local files.
You now have an analysis loop: data plugin drafts, DuckDB on CSV, Postgres when needed, pandas for frames, validate before share.
Send this to the analyst who wants Claude writing SQL without shipping unchecked charts.
Keep this guide
Filed under Claude Code, Dev tools
Questions about this guide
Do I need a warehouse MCP to use the data plugin?
No. The README says you can paste SQL results or upload CSV/Excel. A warehouse MCP (Snowflake, BigQuery, and similar) lets Claude run queries end to end.
How does DuckDB read a CSV without a CREATE TABLE first?
DuckDB's CSV overview shows SELECT * FROM 'flights.csv' and read_csv(...). You can also CREATE TABLE AS SELECT * FROM read_csv('sales.csv').
Where do spreadsheet-only workflows live on this site?
Use Choose five tools for spreadsheet data for local sheet tooling, and Claude Code for finance when the analysis is variance or board packs.
Should pandas replace SQL here?
Use pandas when the working set is already in Python and you need DataFrame transforms. Prefer DuckDB or Postgres SQL when the check is a reusable query against files or a database.
Sources
- Anthropic Data Analyst plugin README, accessed 2026-11-26raw.githubusercontent.com
- PostgreSQL docs: Querying a Table, accessed 2026-11-26postgresql.org
- pandas 10 minutes guide, accessed 2026-11-26pandas.pydata.org
- Claude Code best practices, accessed 2026-11-26code.claude.com
- Full Byte Developer: Choose five tools for spreadsheet datafullbytedeveloper.com
- Full Byte Developer: Claude Code for financefullbytedeveloper.com