
attach-db
Attach a DuckDB database file for use with /duckdb-skills:query. Explores the schema (tables, columns, row counts) and writes a SQL state file so subsequent queries can restore this session automatically via duckdb -init.
- Installs
- 1K
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/duckdb/duckdb-skills --skill attach-db- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads attach-db automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
You are helping the user attach a DuckDB database file for interactive querying.
Database path given: $0
Follow these steps in order, stopping and reporting clearly if any step fails.
State file convention: see the "Resolve state directory" section below. All skills share a single state.sql file per project. Once resolved, any skill can use it with duckdb -init "$STATE_DIR/state.sql" -c "<QUERY>".
Step 1 — Resolve the database path
If $0 is a relative path, resolve it against $PWD to get an absolute path (RESOLVED_PATH).
RESOLVED_PATH="$(cd "$(dirname "$0")" 2>/dev/null && pwd)/$(basename "$0")"
Check the file exists:
test -f "$RESOLVED_PATH"
- File exists -> continue to Step 2.
- File not found -> ask the user if they want to create a new empty database (DuckDB creates the file on first write). If yes, continue. If no, stop.
Step 2 — Check DuckDB is installed
command -v duckdb
If not found, delegate to /duckdb-skills:install-duckdb and then continue.
Step 3 — Validate the database
duckdb "$RESOLVED_PATH" -c "PRAGMA version;"
- Success -> continue.
- Failure -> report the error clearly (e.g. corrupt file, not a DuckDB database) and stop.
Step 4 — Explore the schema
First, list all tables:
duckdb "$RESOLVED_PATH" -csv -c "
SELECT table_name, estimated_size
FROM duckdb_tables()
ORDER BY table_name;
"
If the database has no tables, note that it is empty and skip to Step 5.
For each table discovered (up to 20), run:
duckdb "$RESOLVED_PATH" -csv -c "
DESCRIBE <table_name>;
SELECT count() AS row_count FROM <table_name>;
"
Collect the column definitions and row counts for the summary.
Step 5 — Resolve the state directory
Check if a state file already exists in either location:
# Option 1: in the project directory
test -f .duckdb-skills/state.sql && STATE_DIR=".duckdb-skills"
# Option 2: in the home directory, scoped by project root path
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")"
PROJECT_ID="$(echo "$PROJECT_ROOT" | tr '/' '-')"
test -f "$HOME/.duckdb-skills/$PROJECT_ID/state.sql" && STATE_DIR="$HOME/.duckdb-skills/$PROJECT_ID"
If neither exists, ask the user:
Where would you like to store the DuckDB session state for this project?
- In the project directory (
.duckdb-skills/state.sql) — colocated with the project, easy to find. You can choose to gitignore it.- In your home directory (
~/.duckdb-skills/<project-id>/state.sql) — keeps the project directory clean.
Based on their choice:
Option 1:
STATE_DIR=".duckdb-skills"
mkdir -p "$STATE_DIR"
Then ask: "Would you like to gitignore .duckdb-skills/?" If yes:
echo '.duckdb-skills/' >> .gitignore
Option 2:
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")"
PROJECT_ID="$(echo "$PROJECT_ROOT" | tr '/' '-')"
STATE_DIR="$HOME/.duckdb-skills/$PROJECT_ID"
mkdir -p "$STATE_DIR"
Step 6 — Append to the state file
state.sql is a shared, accumulative init file used by all duckdb-skills. It may already contain macros, LOAD statements, secrets, or other ATTACH statements written by other skills. Never overwrite it — always check for duplicates and append.
Derive the database alias from the filename without extension (e.g. my_data.duckdb → my_data). Check if this ATTACH already exists:
grep -q "ATTACH.*RESOLVED_PATH" "$STATE_DIR/state.sql" 2>/dev/null
If not already present, append:
cat >> "$STATE_DIR/state.sql" <<'STATESQL'
ATTACH IF NOT EXISTS 'RESOLVED_PATH' AS my_data;
USE my_data;
STATESQL
Replace RESOLVED_PATH and my_data with the actual values. If the alias would conflict with an existing one in the file, ask the user for a name.
Step 7 — Verify the state file works
duckdb -init "$STATE_DIR/state.sql" -c "SHOW TABLES;"
If this fails, fix the state file and retry.
Step 8 — Report
Summarize for the user:
- Database path: the resolved absolute path
- Alias: the database alias used in the state file
- State file: the resolved
STATE_DIR/state.sqlpath - Tables: name, column count, row count for each table (or note the DB is empty)
- Confirm the database is now active for
/duckdb-skills:query
If the database is empty, suggest creating tables or importing data.
FAQ
What does the attach-db skill do?
Attach a DuckDB database file for use with /duckdb-skills:query. Explores the schema (tables, columns, row counts) and writes a SQL state file so subsequent queries can restore this session automatically via duckdb -init.
How do I install attach-db?
Run npx skills add https://github.com/duckdb/duckdb-skills --skill attach-db in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/attach-db/ (personal) or .claude/skills/attach-db/ (project).
Which AI agents can use attach-db?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is attach-db safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains attach-db?
It is published by duckdb in duckdb/duckdb-skills. It has 1,041 recorded installs.
More from duckdb/duckdb-skills
query
duckdb/duckdb-skills
Run SQL queries against the attached DuckDB database or ad-hoc against files. Accepts raw SQL or natural language questions. Uses DuckDB Friendly SQL idioms.
duckdb-docs
duckdb/duckdb-skills
Search DuckDB and DuckLake documentation and blog posts. Returns relevant doc chunks for a question or keyword using full-text search against a locally cached index.
read-file
duckdb/duckdb-skills
Read any data file (CSV, JSON, Parquet, Avro, Excel, spatial, SQLite) or remote URL (S3, HTTPS). Use when user references a data file, asks "what's in this file", or wants to preview/profile a dataset. Not for source code.
install-duckdb
duckdb/duckdb-skills
Install or update DuckDB extensions. Each argument is either a plain extension name (installs from core) or name@repo (e.g. magic@community). Pass --update to update extensions instead of installing.
read-memories
duckdb/duckdb-skills
Search past Claude Code session logs to recall prior decisions, patterns, or unresolved work. Use when user says "do you remember", "what did we do", references past conversations, or you need context from prior sessions.
convert-file
duckdb/duckdb-skills
Convert any data file to another format: CSV, Parquet, JSON, Excel, GeoJSON, and more. Use when the user says "convert to parquet", "save as xlsx", "export as JSON", "make this a CSV", "turn into parquet", or any variation of format-to-format conversion for data files. Also triggers when the user wants to write Parquet, Excel, or other binary formats that Claude cannot produce natively.
Popular data & databases skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-client-api
prisma/skills
Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".
prisma-database-setup
prisma/skills
Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.
prisma-cli
prisma/skills
Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.
prisma-postgres
prisma/skills
Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.
prisma-driver-adapter-implementation
prisma/skills
Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.