hoavdc/CodexKit / skills/codexkit-sql-query-builder
codexkit-sql-query-builder
UnverifiedBuild production-ready analytical SQL queries using CTEs, window functions, aggregations, and data transformations. Translates business questions into well-documented, performant queries. Use when writing reporting queries, building data pipelines, or answering ad-hoc business questions with SQL.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.0 KB |
| agents/openai.yaml | config | 168 B |
| examples/common-mistakes.md | markdown | 842 B |
| examples/good-output.md | markdown | 1.2 KB |
| scripts/query-validator.sql | other | 3.6 KB |
| verification/checklist.md | markdown | 1.4 KB |
scripts/query-validator.sql
View on GitHub-- query-validator.sql
-- Validates common SQL anti-patterns and performance issues.
-- Run against your query before shipping to production.
--
-- Usage: Replace {YOUR_QUERY} with your CTE/subquery to analyze.
-- Execute each section independently against your database.
-- ============================================================
-- 1. EXPLAIN ANALYZE — Check execution plan
-- ============================================================
-- Look for:
-- - Seq Scan on large tables (should be Index Scan)
-- - Nested Loop on large result sets (consider Hash Join)
-- - Sort operations without index support
-- - Row estimates vs actuals differ by >10x
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
-- {YOUR_QUERY}
;
-- ============================================================
-- 2. NULL safety check — Identify WHERE clause null traps
-- ============================================================
-- Common trap: WHERE column != 'value' silently excludes NULLs
-- Fix: WHERE (column != 'value' OR column IS NULL)
-- Check for NULLs in your join/filter columns:
SELECT
'orders.customer_id' AS column_name,
COUNT(*) AS total_rows,
COUNT(customer_id) AS non_null,
COUNT(*) - COUNT(customer_id) AS null_count,
ROUND(100.0 * (COUNT(*) - COUNT(customer_id)) / NULLIF(COUNT(*), 0), 2) AS null_pct
FROM orders
-- Repeat for each critical column
;
-- ============================================================
-- 3. Cardinality explosion detector
-- ============================================================
-- JOINs can multiply rows unexpectedly.
-- Compare row counts before and after each JOIN step.
-- Step 1: Base table count
SELECT 'base' AS step, COUNT(*) AS rows FROM orders;
-- Step 2: After first JOIN
SELECT 'after_join_1' AS step, COUNT(*) AS rows
FROM orders
JOIN products ON orders.product_id = products.id;
-- If rows increased, you have a many-to-many join.
-- Fix: Add DISTINCT, GROUP BY, or review join keys.
-- ============================================================
-- 4. Index coverage check
-- ============================================================
-- Verify your WHERE and JOIN columns have indexes.
SELECT
t.relname AS table_name,
a.attname AS column_name,
CASE WHEN i.indexrelid IS NOT NULL THEN '✓ Indexed' ELSE '✗ No Index' END AS index_status
FROM pg_attribute a
JOIN pg_class t ON a.attrelid = t.oid
JOIN pg_namespace n ON t.relnamespace = n.oid
LEFT JOIN pg_index i ON i.indrelid = t.oid
AND a.attnum = ANY(i.indkey)
WHERE n.nspname = 'public'
AND t.relname IN ('orders', 'products', 'customers') -- your tables
AND a.attname IN ('customer_id', 'product_id', 'order_date') -- your filter/join columns
AND a.attnum > 0
ORDER BY t.relname, a.attname;
-- ============================================================
-- 5. Data type mismatch detector
-- ============================================================
-- Implicit casts in JOINs/WHEREs prevent index usage.
-- Example: WHERE varchar_col = 123 (implicit cast, no index)
SELECT
c1.table_name AS left_table,
c1.column_name AS left_column,
c1.data_type AS left_type,
c2.table_name AS right_table,
c2.column_name AS right_column,
c2.data_type AS right_type,
CASE WHEN c1.data_type != c2.data_type THEN '⚠ TYPE MISMATCH' ELSE '✓ OK' END AS status
FROM information_schema.columns c1
JOIN information_schema.columns c2
ON c1.column_name = c2.column_name
AND c1.table_name != c2.table_name
WHERE c1.table_schema = 'public'
AND c2.table_schema = 'public'
AND c1.table_name < c2.table_name -- avoid duplicates
ORDER BY status DESC, c1.column_name;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 117k | Updated | Claude CodeCodex | Unverified | Install |