Skip to main content
AIDiveForge AIDiveForge
🗃️

SQL Query Writer

Code & Development · by AIDiveForge · Apr 17, 2026 · Intermediate · ✓ 1 verified compat

Draft one read-only SQL query grounded in a supplied schema and dialect.

Get SQL, bound parameters, assumptions and a safe validation plan.

Free · 2 KB · SKILL.md, instructions and example files. Provide the database dialect and schema. Database execution requires your existing authorization.

A worked example

A small example to try before using your own data.

Input

{
  "dialect": "PostgreSQL",
  "schema": "orders(id int primary key, customer_id int, total_cents int, status text)",
  "request": "Paid revenue per customer, highest first"
}

Expected result

{
  "sql": "SELECT customer_id, SUM(total_cents) AS revenue_cents FROM orders WHERE status = $1 GROUP BY customer_id ORDER BY revenue_cents DESC, customer_id;",
  "parameters": [
    "paid"
  ],
  "execution": "Not run against a database"
}

What to check: Use only supplied identifiers; preserve cents as integers; parameterize status; include deterministic tie ordering.

Limits: A plausible query is not a verified report. Permission checks, performance and tenant filters must be confirmed against the actual database.

Worked example included. Model-specific performance and vendor compatibility have not been benchmarked.

Installation options and other formats

Install this skill

An agent skill starts with SKILL.md. The ZIP also includes its examples and any helper scripts. Drop the file into your tool of choice — or pick a different format if you use Cursor, Windsurf, Copilot, or something else.

Download SKILL.md
python3 - <<'ADF_SKILL_INSTALL'
import hashlib, io, os, stat, tempfile, urllib.request, zipfile
from pathlib import Path, PurePosixPath
folder = "sql-query-writer"
root = Path(os.environ.get('ADF_SKILL_ROOT', str(Path.home() / '.claude' / 'skills'))).expanduser()
destination = root / folder
if destination.exists() or destination.is_symlink():
    raise SystemExit('An installation already exists. Back it up and merge the ZIP deliberately.')
root.mkdir(parents=True, exist_ok=True)
request = urllib.request.Request("https://aidiveforge.com/skill/sql-query-writer.zip", headers={'User-Agent': 'AIDiveForge-Resource-Installer/1.0 (+https://aidiveforge.com/skills/)'})
with urllib.request.urlopen(request, timeout=30) as response:
    data = response.read(8 * 1024 * 1024 + 1)
if len(data) > 8 * 1024 * 1024 or hashlib.sha256(data).hexdigest() != "aec84094ecdb20de9a69539b1b1a158214a5db395518e7bc1f6a8762d7b679ae":
    raise SystemExit('The download did not match this reviewed bundle. No files were installed.')
with zipfile.ZipFile(io.BytesIO(data)) as archive, tempfile.TemporaryDirectory(prefix='.adf-skill-', dir=root) as temporary:
    members = archive.infolist()
    if len(members) > 100 or sum(m.file_size for m in members) > 16 * 1024 * 1024:
        raise SystemExit('Unexpected archive size')
    for member in members:
        name = PurePosixPath(member.filename)
        if name.is_absolute() or '..' in name.parts or not name.parts or name.parts[0] != folder or '\\' in member.filename or stat.S_ISLNK(member.external_attr >> 16):
            raise SystemExit('Unsafe archive entry; nothing was installed')
        target = Path(temporary).joinpath(*name.parts)
        if member.is_dir():
            target.mkdir(parents=True, exist_ok=True)
        else:
            target.parent.mkdir(parents=True, exist_ok=True)
            with target.open('xb') as stream:
                stream.write(archive.read(member))
    staged = Path(temporary) / folder
    if not (staged / 'SKILL.md').is_file() or destination.exists() or destination.is_symlink():
        raise SystemExit('The skill could not be installed without replacing existing data')
    os.rename(staged, destination)
print('Installed the complete skill folder:', destination)
ADF_SKILL_INSTALL

Claude Code: ~/.claude/skills/sql-query-writer/SKILL.md. Codex: ~/.codex/skills/sql-query-writer/SKILL.md. Keep the complete ZIP folder when helper scripts are included.

🧠 Why it works

Use only supplied identifiers; preserve cents as integers; parameterize status; include deterministic tie ordering.

⚙️ How it works

  1. Read table definitions, keys, nullability and the intended reporting grain. Ask for a missing join key rather than inventing it.
  1. Map each requested metric to its source and aggregation. Check join cardinality before summing money or counts.
  1. Write a single SELECT or read-only CTE using bound parameters. Keep identifiers fixed from the schema.
  1. Check syntax with the available dialect parser or EXPLAIN in an authorized read-only session. Report when no database check ran.
  1. Show a tiny input/output example and call out null handling, timezone and duplicate-row risks.

Description

Get SQL, bound parameters, assumptions and a safe validation plan.

Provide the database dialect and schema. Database execution requires your existing authorization.

Limits: A plausible query is not a verified report. Permission checks, performance and tenant filters must be confirmed against the actual database.

Recommended Use

Tools and workflow packs this skill pairs well with. Forge picks are auto-generated from category + capability signals; Community picks are added by people who've used the pairing.