# 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.

Source: https://fullbytedeveloper.com/blog/claude-code-for-data-analysis-sql
Published here: 2026-11-26, updated 2026-11-26

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](/blog/claude-code-spreadsheet-data-tools), [Claude Code for finance](/blog/claude-code-for-finance). Browse the [Claude Code topic](https://fullbytedeveloper.com/blog/topic/claude-code).

## Install the data plugin, then pin the grain

```bash
claude plugin marketplace add anthropics/knowledge-work-plugins
claude plugin install data@knowledge-work-plugins
```

Commands 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]

```text
/explore-data orders_2026_11.csv
/write-query cohort retention by signup month, DuckDB dialect
/validate before sharing the revenue trend note
```

Tell 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]

```sql
SELECT product, sum(quantity * price) AS revenue
FROM read_csv('sales.csv')
GROUP BY product
ORDER BY revenue DESC;
```

```sql
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]

```sql
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]

```python
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](/blog/claude-code-for-finance). [8]

## Validate before anyone else sees the chart

1. `/explore-data` notes null rates and odd enums. [3]
2. DuckDB (or warehouse) query returns row count and sum checksums. [1] [2]
3. `/validate` reviews methodology and bias flags before share. [3]
4. Person signs the note; agent does not email stakeholders alone. [6]

For sheet-native tooling, use [Choose five tools for spreadsheet data](/blog/claude-code-spreadsheet-data-tools). [7]

When the data sits in Amazon Redshift, [set up the DuckDB Redshift extension and join local files](/blog/duckdb-redshift-extension-setup).

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.

## Sources

1. [DuckDB quickstart (docs 2.0), accessed 2026-11-26](https://duckdb.org/docs/2.0/quickstart)
2. [DuckDB CSV overview (docs 2.0), accessed 2026-11-26](https://duckdb.org/docs/2.0/data/csv/overview)
3. [Anthropic Data Analyst plugin README, accessed 2026-11-26](https://raw.githubusercontent.com/anthropics/knowledge-work-plugins/main/data/README.md)
4. [PostgreSQL docs: Querying a Table, accessed 2026-11-26](https://www.postgresql.org/docs/current/tutorial-select.html)
5. [pandas 10 minutes guide, accessed 2026-11-26](https://pandas.pydata.org/docs/user_guide/10min.html)
6. [Claude Code best practices, accessed 2026-11-26](https://code.claude.com/docs/en/best-practices)
7. [Full Byte Developer: Choose five tools for spreadsheet data](https://fullbytedeveloper.com/blog/claude-code-spreadsheet-data-tools)
8. [Full Byte Developer: Claude Code for finance](https://fullbytedeveloper.com/blog/claude-code-for-finance)
