skills/sql-ops/SKILL.md
Quick reference for common SQL patterns, CTEs, window functions, and indexing strategies. Triggers on: sql patterns, cte example, window functions, sql join, index strategy, pagination sql.
npx skillsauth add 0xDarkMatter/claude-mods sql-opsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Quick reference for common SQL patterns.
WITH active_users AS (
SELECT id, name, email
FROM users
WHERE status = 'active'
)
SELECT * FROM active_users WHERE created_at > '2024-01-01';
WITH
active_users AS (
SELECT id, name FROM users WHERE status = 'active'
),
user_orders AS (
SELECT user_id, COUNT(*) as order_count
FROM orders GROUP BY user_id
)
SELECT u.name, COALESCE(o.order_count, 0) as orders
FROM active_users u
LEFT JOIN user_orders o ON u.id = o.user_id;
| Function | Use |
|----------|-----|
| ROW_NUMBER() | Unique sequential numbering |
| RANK() | Rank with gaps (1, 2, 2, 4) |
| DENSE_RANK() | Rank without gaps (1, 2, 2, 3) |
| LAG(col, n) | Previous row value |
| LEAD(col, n) | Next row value |
| SUM() OVER | Running total |
| AVG() OVER | Moving average |
SELECT
date,
revenue,
LAG(revenue, 1) OVER (ORDER BY date) as prev_day,
SUM(revenue) OVER (ORDER BY date) as running_total
FROM daily_sales;
| Type | Returns |
|------|---------|
| INNER JOIN | Only matching rows |
| LEFT JOIN | All left + matching right |
| RIGHT JOIN | All right + matching left |
| FULL JOIN | All rows, NULL where no match |
-- OFFSET/LIMIT (simple, slow for large offsets)
SELECT * FROM products ORDER BY id LIMIT 20 OFFSET 40;
-- Keyset (fast, scalable)
SELECT * FROM products WHERE id > 42 ORDER BY id LIMIT 20;
| Level | Dirty Read | Non-Repeatable Read | Phantom Read | Use |
|-------|-----------|--------------------|--------------|-----|
| READ UNCOMMITTED | Possible | Possible | Possible | Rarely (PostgreSQL treats as READ COMMITTED) |
| READ COMMITTED | No | Possible | Possible | Default in most databases |
| REPEATABLE READ | No | No | Possible* | Consistent multi-statement reads |
| SERIALIZABLE | No | No | No | Critical invariants (retry on serialization failure) |
*PostgreSQL's REPEATABLE READ also prevents phantoms via snapshot isolation.
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
-- ... critical operations ...
COMMIT; -- be prepared to retry on serialization failure
Keep the default READ COMMITTED globally; raise the level per-transaction only where the logic requires it.
| Index Type | Best For | |------------|----------| | B-tree | Range queries, ORDER BY | | Hash | Exact equality only | | GIN | Arrays, JSONB, full-text | | Covering | Avoid table lookup |
| Mistake | Fix |
|---------|-----|
| SELECT * | List columns explicitly |
| WHERE YEAR(date) = 2024 | WHERE date >= '2024-01-01' |
| NOT IN with NULLs | Use NOT EXISTS |
| N+1 queries | Use JOIN or batch |
For detailed patterns, load:
./references/window-functions.md - Complete window function patterns./references/indexing-strategies.md - Index types, covering indexes, optimizationtesting
Audit any repo against the agentic-quality doctrine — score entry docs, structure, and enforcement gates, then map each finding to its fix. Triggers on: repo doctor, repo audit, agentic quality, is this repo agent-friendly, doc drift, stale AGENTS.md, monorepo structure, nested CLAUDE.md.
data-ai
Router for parallel or recurring agent work across six skills. Covers: parallel agents, fan out work, delegate to workers, run overnight, scheduled loop, land branches, mixed-model fleet, orchestrate workers, background agents at scale. Triggers on: which skill for parallel work, fan out agents, spawn workers, run this overnight, schedule a loop, land my branches, heterogeneous fleet, delegate to cheaper model, autonomous loop.
tools
Heterogeneous cross-provider fleet - GLM (z.ai), Codex (OpenAI), Grok (xAI), Anthropic Sonnet/Opus/Haiku - from one session, porting the native Workflow tool's patterns (adversarial verify, judge panels, journal resume) to OS-process workers. Triggers: fleetflow, heterogeneous/mixed-model fleet, codex worker, grok worker, cross-provider fan-out, cross-model verify.
development
Application/game-scale three.js: ES modules, GLTF pipeline (DRACO/KTX2/meshopt), AnimationMixer, physics (rapier/cannon-es), react-three-fiber, and performance at scale (InstancedMesh, LOD, draw calls). Triggers on: three.js, GLTFLoader, r3f, game loop, WebGL memory leak, boids.