Agent skill

SQL Idioms

by irahardianto in irahardianto/awesome-agv

SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns.

MITAuto-check passedDatabases

Install SQL Idioms

skills CLI
$ npx skills add irahardianto/awesome-agv --skill sql-idioms -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install irahardianto/awesome-agv sql-idioms --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/irahardianto/awesome-agv.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/sql-idioms .claude/skills/sql-idioms && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
sql-idioms
GitHub stars
157
Token cost
~1.5k tokens
SKILL.md length
418 words
Files
1
Skills in repo
34
Repo updated
First seen
Licence
MIT

At a glance

SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns.

  • Works in 4 steps: CTEs over subqueries for readability → Window functions for ranking, running… → Explicit JOIN syntax — never implicit… → …
  • Writing complex queries
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Analyzing performance

What it does

SQL Idioms is an agent skill from irahardianto/awesome-agv. SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns. Use when writing complex queries, analyzing performance, or drafting database migrations.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering SQL, Database migrations and Code quality. It works with SQL and PostgreSQL. The repository describes itself as: Comprehensive sets of standards and practices designed to elevate the capabilities of AI coding agents. The licence is MIT.

When your agent uses it

  • Writing complex queries
  • Analyzing performance
  • Drafting database migrations

Example prompts

  • “/sql-idioms”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. CTEs over subqueries for readability
  2. Window functions for ranking, running totals
  3. Explicit JOIN syntax — never implicit joins in WHERE.
  4. Parameterized queries — never string concatenation. (See .agents/rules/security-mandate.md.)

What it can do on your machine

Read from SKILL.md and the folder at commit 9e997ba. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

SQL Idioms loads about 1.5k tokens when it runs. Until then it costs about 64 tokens; SKILL.md has 418 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~64
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from irahardianto/awesome-agv at commit 9e997ba, republished under its MIT licence (© irahardianto). 418 words, ~1,518 tokens.

Download SKILL.mdSave it as .claude/skills/sql-idioms/SKILL.md (or your agent's skills folder).
name
sql-idioms
description
SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns. Use when writing complex queries, analyzing performance, or drafting database migrations.

SQL Idioms and Patterns

SQL rewards set-based thinking, explicit joins, and query plan awareness. Idiomatic SQL = readable, performant, migration-safe.

Scope: SQL coding idioms. For database design principles, load @.agents/rules/database-design-principles.md.

Query Patterns
  1. CTEs over subqueries for readability:

    sql
    -- ✅ CTE — readable, debuggable
    WITH active_tasks AS (
        SELECT id, title, priority, user_id
        FROM tasks
        WHERE status = 'active'
    )
    SELECT u.name, COUNT(at.id) AS task_count
    FROM users u
    JOIN active_tasks at ON u.id = at.user_id
    GROUP BY u.name;
    
    -- ❌ Nested subquery — hard to read
    SELECT u.name, (SELECT COUNT(*) FROM tasks t WHERE t.user_id = u.id AND t.status = 'active')
    FROM users u;
  2. Window functions for ranking, running totals:

    sql
    SELECT title, priority,
        ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) AS rn
    FROM tasks;
  3. Explicit JOIN syntax — never implicit joins in WHERE.

  4. Parameterized queries — never string concatenation. (See .agents/rules/security-mandate.md.)

Migration Safety

For migration strategy (additive-first, two-phase drops, reversibility), see @.agents/rules/database-design-principles.md § Migrations.

  1. Index creation: CONCURRENTLY on PostgreSQL for zero-downtime.
  2. Idempotent DDL — use IF NOT EXISTS for tables/indexes; DO $$ ... pg_constraint check ... $$ for constraints.
Index Strategy
  1. Choose the right index type:

    • B-tree (default): =, <, >, BETWEEN, IN, IS NULL
    • GIN: arrays, JSONB (@>), full-text search (@@)
    • GiST: geometric data, range types, nearest-neighbor (KNN)
    • BRIN: large time-series tables (10-100x smaller than B-tree)
    • Hash: equality-only (marginally faster than B-tree for =)
  2. Composite indexes — column order matters:

    sql
    -- Equality columns first, range columns last (leftmost prefix rule)
    CREATE INDEX idx ON orders (status, created_at);
    -- Works for: WHERE status = 'pending'
    -- Works for: WHERE status = 'pending' AND created_at > '2024-01-01'
    -- Does NOT work for: WHERE created_at > '2024-01-01' (alone)
  3. Partial indexes for filtered queries:

    sql
    -- Index only active rows (5-20x smaller)
    CREATE INDEX idx_users_active_email ON users (email) WHERE deleted_at IS NULL;
  4. Covering indexes to avoid heap fetches:

    sql
    -- INCLUDE non-searchable columns for index-only scans
    CREATE INDEX idx_orders_status ON orders (status) INCLUDE (customer_id, total);
  5. Indexes on foreign keys — always. PostgreSQL does not auto-index FKs.

Performance
  1. EXPLAIN (ANALYZE, BUFFERS) before optimizing — never guess.

    • Seq Scan on large table = missing index
    • Rows Removed by Filter = poor selectivity
    • read >> hit in Buffers = data not cached
    • Sort Method: external merge = work_mem too low
  2. Avoid SELECT * — list specific columns.

  3. Keyset pagination over OFFSET for large datasets:

    sql
    -- O(1) regardless of page depth
    SELECT * FROM products WHERE (created_at, id) > ($1, $2)
    ORDER BY created_at, id LIMIT 20;

    Use LIMIT/OFFSET only for small, bounded result sets.

Show full SKILL.md (277 more words)Show less
Concurrency & Locking
  1. Prevent deadlocks — consistent lock ordering:

    sql
    -- Acquire locks in PK order before updating
    SELECT * FROM accounts WHERE id IN (1, 2) ORDER BY id FOR UPDATE;
  2. SKIP LOCKED for queue processing:

    sql
    -- Workers skip locked rows instead of blocking (10x throughput)
    UPDATE jobs SET status = 'processing'
    WHERE id = (
      SELECT id FROM jobs WHERE status = 'pending'
      ORDER BY created_at LIMIT 1 FOR UPDATE SKIP LOCKED
    ) RETURNING *;
  3. Advisory locks for application-level coordination:

    sql
    SELECT pg_advisory_xact_lock(hashtext('daily_report')); -- Released on COMMIT
  4. statement_timeout — always set per-session to prevent runaway queries.

Data Operations
  1. UPSERT — atomic insert-or-update (no race conditions):

    sql
    INSERT INTO settings (user_id, key, value) VALUES ($1, $2, $3)
    ON CONFLICT (user_id, key)
    DO UPDATE SET value = EXCLUDED.value, updated_at = now();
  2. Bulk loading — use COPY over batch INSERTs for large imports.

  3. Batch inserts — multiple rows per statement, not one INSERT per row.

Diagnostics
  1. pg_stat_statements — enable to identify top resource-consuming queries by total time and call frequency.

  2. VACUUM/ANALYZE — run ANALYZE after large data changes. Tune autovacuum_vacuum_scale_factor for high-churn tables.

Advanced PostgreSQL
  1. Full-text search: use tsvector + GIN index, not LIKE '%term%'.
  2. JSONB indexing: GIN (jsonb_path_ops for @> only — 2-3x smaller), expression indexes for key lookups.
Naming

Follow conventions in @.agents/rules/database-design-principles.md § Schema (Naming).

Anti-Patterns
  • ❌ Missing indexes on foreign keys
  • ❌ N+1 queries (use JOIN or batch)
  • ❌ String concatenation in queries (SQL injection risk)
  • ❌ Storing comma-separated values in a single column
  • ❌ OFFSET pagination on large datasets (use keyset)
  • ❌ timestamp without timezone (use timestamptz)
  • ❌ varchar(n) without reason (use text)
  • ❌ Random UUID v4 as primary key on large tables (index fragmentation)
  • ❌ Check-then-insert pattern (race condition — use UPSERT)
  • Database Design Principles @.agents/rules/database-design-principles.md
  • Security Principles .agents/rules/security-principles.md
  • Performance Optimization Principles @.agents/rules/performance-optimization-principles.md

© irahardianto, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/sql-idioms of irahardianto/awesome-agv.

Open the folder on GitHubat commit 9e997ba

Compare with similar skills

SQL Idioms next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

SQL Idioms compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL Idioms this skillirahardianto/awesome-agv157—~1.5kAutomated safety check: PassMIT
Database Migrations SQL Migrationsrmyndharis/antigravity-skills1.7k3 repos~577Automated safety check: NotesMIT
Diesel Guardayarotsky/diesel-guard121—~3.1kAutomated safety check: PassMIT
DB ContextSilvioBaratto/optimizer176—~6.4kAutomated safety check: NotesCustom licence
Postgrestimescale/pg-aiguide1.9k—~941Automated safety check: PassApache-2.0
Database MigrationRain-kl/OpenFlare288—~1.3kAutomated safety check: PassApache-2.0

Similar skills

  • Database Migrations SQL Migrations

    rmyndharis/antigravity-skills

    SQL database migrations with zero-downtime strategies for PostgreSQL, MySQL, SQL Server

    1.7k GitHub starsUsed in 3 repos~577 tokens
    DatabasesAuto-check: notes
  • Diesel Guard

    ayarotsky/diesel-guard

    Lints Diesel and SQLx Postgres migrations for unsafe schema changes that lock tables or cause downtime, and authors custom Rhai checks.

    121 GitHub stars~3.1k tokensUpdated 10 days ago
    DatabasesAuto-check passed
  • DB Context

    SilvioBaratto/optimizer

    Complete knowledge of the optimizer PostgreSQL database: 57 ingestion tables, schema, relationships, live row counts, query patterns, and conventions.

    176 GitHub stars~6.4k tokensUpdated yesterday
    DatabasesAuto-check: notes
  • Postgres

    timescale/pg-aiguide

    A skill your agent uses for any PostgreSQL database work — table design, indexing, data types, constraints, extensions (pgvector, PostGIS, TimescaleDB), search, and migrations.

    1.9k GitHub stars~941 tokensUpdated yesterday
    DatabasesAuto-check passed
  • Database Migration

    Rain-kl/OpenFlare

    Wavelet 项目专用:当新增或修改数据库表结构、索引、初始化数据、系统配置 seed、模板 seed、默认管理员、goose SQL 迁移、internal/infra/persistence/migrator、ClickHouse 分析库 DDL 或数据库升级流程时必须使用。本技能指导在 internal/infra/persistence/migrator/goose 下编写…

    288 GitHub stars~1.3k tokensUpdated today
    DatabasesAuto-check passed
  • Database Marchat

    Cod-e-Codes/marchat

    Changes marchat SQL schema and queries across SQLite, PostgreSQL, and MySQL using dialect helpers.

    137 GitHub stars~985 tokensUpdated 5 days ago
    DatabasesAuto-check passed

More from irahardianto/awesome-agv

All 34 skills in this repo
  • Distinctive Frontend Design Builder

    irahardianto/awesome-agv

    Commits to one bold aesthetic direction, sets up a CSS token system for it, then builds the interface in Vue or plain HTML using those tokens.

    157 GitHub stars~2.4k tokensUpdated 3 days ago
    Auto-check passed
  • Perf Optimization

    irahardianto/awesome-agv

    Profile-driven performance optimization protocol. An agent skill from irahardianto/awesome-agv.

    157 GitHub stars~4.3k tokensUpdated 3 days ago
    Auto-check passed
  • Angular Idioms and Patterns

    irahardianto/awesome-agv

    Coding conventions for Angular 19 and later: standalone components, signals, OnPush change detection, lazy routes and where RxJS still belongs.

    157 GitHub stars~3.8k tokensUpdated 3 days ago
    Auto-check passed
  • CI/CD Pipeline Principles

    irahardianto/awesome-agv

    Rules for designing CI/CD pipelines in layers: universal lint, test and scan stages, container builds with SBOM attestation, and GitOps for orchestrated deployments.

    157 GitHub stars~2.7k tokensUpdated 3 days ago
    Auto-check: notes
  • Hono Idioms

    irahardianto/awesome-agv

    Hono lightweight web framework patterns: type-safe route handlers, middleware composition, Zod validation, and RPC clients for Cloudflare Workers, Node, or Bun.

    157 GitHub stars~3k tokensUpdated 3 days ago
    Auto-check passed
  • Mobile Testing

    irahardianto/awesome-agv

    Mobile E2E testing patterns — Flutter integrationtest, Patrol, Maestro, golden testing, device matrix, and test data management.

    157 GitHub stars~1.8k tokensUpdated 3 days ago
    Auto-check: notes

Works with

Categories

Questions about SQL Idioms

What does SQL Idioms do?

SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns. SQL Idioms is an agent skill from irahardianto/awesome-agv. SQL coding standards: CTEs, explicit JOINs, index optimization, query execution plan analysis, transaction locking, and zero-downtime migration patterns.

When should I use SQL Idioms?

SQL Idioms fits situations like: writing complex queries; analyzing performance; drafting database migrations.

How do I install SQL Idioms in Claude Code?

Run `npx skills add irahardianto/awesome-agv --skill sql-idioms -a claude-code`. Or copy the skill folder (.agents/skills/sql-idioms in irahardianto/awesome-agv) into .claude/skills/sql-idioms in your project. Claude Code loads it when a task matches its description.

How do I install SQL Idioms in Codex?

Run `npx skills add irahardianto/awesome-agv --skill sql-idioms -a codex`. Or copy the skill folder (.agents/skills/sql-idioms in irahardianto/awesome-agv) into .agents/skills/sql-idioms in your project. Codex loads it when a task matches its description.

Can I use SQL Idioms in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add irahardianto/awesome-agv --skill sql-idioms -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-idioms, .gemini/skills/sql-idioms, .github/skills/sql-idioms and .opencode/skills/sql-idioms in your project.

What does SQL Idioms need to run?

SKILL.md names no scripts, command-line tools or credentials: SQL Idioms is instructions for the agent only.

Does SQL Idioms access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is SQL Idioms safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does SQL Idioms use?

SQL Idioms is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL Idioms use?

About 1.5k tokens (SKILL.md is roughly 6.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to SQL Idioms?

Skills that share tags, products or a category with SQL Idioms: Database Migrations SQL Migrations (rmyndharis/antigravity-skills, 1.7k stars), Diesel Guard (ayarotsky/diesel-guard, 121 stars), DB Context (SilvioBaratto/optimizer, 176 stars) and Postgres (timescale/pg-aiguide, 1.9k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL Idioms?

irahardianto (a GitHub user) maintains it in irahardianto/awesome-agv, which has 157 GitHub stars. The repository holds 34 skills in this directory. The repository was last updated on October 5, 2026.

Source: irahardianto/awesome-agv on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.