writing-sql

writing-sql is a skill for Claude Code from rileyhilliard/claude-essentials. It costs 50 tokens per session (557 once invoked), scanned A, original, MIT.

A collection of advanced SQL patterns for writing, reviewing, and speeding up database queries, especially in PostgreSQL.

In plain words
What is it for?
It helps with multi-column statistics, indexes, text searches, aggregation, NULL handling, pagination, unexpected duplicate rows, and other query performance issues.
Why use it?
It helps catch query problems that can return wrong results or make searches and reports slower than expected.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the ce plugin — 17 skills, 1 command, 4 agents shipped together

Good fit It helps with multi-column statistics, indexes, text searches, aggregation, NULL handling, pagination, unexpected duplicate rows, and other query performance issues.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rileyhilliard/claude-essentials/writing-sql
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add rileyhilliard/claude-essentials --skill writing-sql
Clone the repo
git clone --depth 1 https://github.com/rileyhilliard/claude-essentials

Made for: Claude Code.

Or install ce, the plugin that ships this one along with the rest of its 17 skills, 1 command, 4 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for writing-sql

README.md
[![agentmods](https://agentmods.dev/badge/skills/rileyhilliard/claude-essentials/writing-sql/github.svg)](https://agentmods.dev/skills/rileyhilliard/claude-essentials/writing-sql)
Your own site
<a href="https://agentmods.dev/skills/rileyhilliard/claude-essentials/writing-sql"><img src="https://agentmods.dev/badge/skills/rileyhilliard/claude-essentials/writing-sql/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for writing-sql

Your own site · 80×15
<a href="https://agentmods.dev/skills/rileyhilliard/claude-essentials/writing-sql"><img src="https://agentmods.dev/badge/skills/rileyhilliard/claude-essentials/writing-sql.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 50 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 557 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00050 $0.00557
Opus 5.5 $0.00020 $0.00223
Sonnet 5.5 $0.00010 $0.00111
Haiku 4.5 $0.00005 $0.00056

Measured 1mo ago against content hash 23cc891a10bf, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

writing-sql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/ce/skills/writing-sql/SKILL.md · 38 lines

How it starts

The opening of the file, as written. The whole thing — 38 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing SQL

Core principle: Every query you write has an execution plan. Write SQL with that plan in mind, not just the result.

This skill covers only what Claude's defaults miss. Topics already handled by managing-databases/postgres-querying.md (LATERAL, CTE materialization, DISTINCT ON, EXPLAIN red flags, ROWS vs RANGE) are not repeated here.

Topic Navigation

Task Load
Planner picking bad plans on multi-column WHERE extended-statistics.md
LIKE search not using index, text pattern matching index-internals.md
Composite index column ordering, INCLUDE clause index-internals.md
Type mismatch between param and column silently bypassing index index-internals.md
Conditional aggregation, pivot queries, subtotals aggregation-patterns.md
GROUPING SETS, ROLLUP, CUBE aggregation-patterns.md
NULL edge cases in aggregates and window functions aggregation-patterns.md
Paginating large result sets query-anti-patterns.md
NOT IN returning zero rows unexpectedly query-anti-patterns.md
DISTINCT added to fix duplicate rows query-anti-patterns.md
Correlated subqueries in SELECT list query-anti-patterns.md
Functions in WHERE bypassing indexes query-anti-patterns.md

Iron Rules

These apply to every query, no exceptions:

  • Never paginate with OFFSET on large tables. Use keyset pagination.
  • Never use NOT IN when the subquery column is nullable. Use NOT EXISTS.
  • Always match parameter types to column types exactly. Implicit casts bypass indexes.
  • Replace CASE WHEN inside aggregates with FILTER. It's cleaner and semantically correct.
  • When a multi-column WHERE produces bad estimates, add extended statistics before adding hints or rewrites.

Read the full file on GitHub · 38 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 38 lines · 50 tokens per session scan A 23cc891a10bf

Subscribe to this mod's changes

writing-sql is a skill published in the GitHub repository rileyhilliard/claude-essentials (130 stars, last pushed 2mo ago), licensed MIT. It adds 50 tokens to every session and 557 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

azure-resource-manager-postgresql-dotnet

Azure PostgreSQL Flexible Server SDK for .NET. Database management for PostgreSQL Flexible Server deployments. Use for creating servers, databases, firewall rules, configurations, backups, and high availability. Triggers: "PostgreSQL", "PostgreSqlFlexibleServer", "PostgreSQL Flexible Server", "Azure Database for…

microsoft/skills · 97 tokens

jpa-patterns

JPA/Hibernate patterns and common pitfalls (N+1, lazy loading, transactions, queries). Use when user has JPA performance issues, LazyInitializationException, or asks about entity relationships and fetching strategies.

piomin/claude-ai-spring-boot · 47 tokens

ecto-patterns

Use when a task touches Ecto, even a how-to question: schemas, changesets, validations, queries, preloads, Multi, migrations, constraints, money fields. Load it before writing Ecto code. Skip for Ash.

oliver-kriska/claude-elixir-phoenix · 51 tokens

kysely

Guidelines for developing with Kysely, a type-safe TypeScript SQL query builder with autocompletion support.

Mindrally/skills · 26 tokens

sql-query-performance

Use when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination.

makifbaysal/tasktrooper · 35 tokens

sqlsugar

Use when doing multi-database ORM operations in .NET — SQL Server, MySQL, PostgreSQL, SQLite, Oracle with fluent API, code-first, and LINQ. SqlSugar: high-performance .NET ORM supporting 10+ databases.

znlgis/opengis-skills · 53 tokens