sql-style-mlisted
Install: claude install-skill MathCaz/claude-skills
# SQL Style
Two sections: **General SQL rules** (any dialect) and **Snowflake-specific rules** (apply when the target is Snowflake). Some general rules are marked **(aspirational)** — they pull new code toward the standard; legacy code is what it is.
Real-world reference: a well-sectioned feature-engineering model (numbered sections, source CTEs, progressive JOIN CTEs) is the canonical example of these conventions in action — especially the sectioning and progressive-JOIN patterns below.
---
## Section 1 — General SQL rules
### Layout & syntax
- **Keywords UPPERCASE** — `SELECT`, `FROM`, `WHERE`, `INNER JOIN`, `QUALIFY`, etc. (needed for SQL syntax highlighting inside Python string literals).
- **Identifiers lower_snake_case** — `user_id`, `order_date`. No `.` in names. No leading digits.
- **Trailing commas, not leading.**
- **4-space indent** inside SELECT lists, CTE bodies, subqueries, and `ON` continuation lines.
- **Spaces around operators** — `price > 100`, `a.id = b.user_id`.
- **Parentheses for complex logic** — group conditions in WHERE / CASE for clarity.
- **Single quotes for string literals** — `'active'`, `'2026-01-01'`.
### Aliases
- **Always `AS`** for aliases — `users AS usr`, `total AS order_total` *(aspirational)*.
- **Descriptive initials** — `usr`, `ord`, `prd`, `evt` — **never single letters** (`u`, `o`, `a`).
- **Cap at 3 letters**; extend to 4 only when 3 would collide (e.g., `payments` vs `payouts` → `pmt` / `pyt`).
- **Same length per CTE/bloc