What problem does it solve?
Writing maintainable SQL is hard: inconsistent formatting, missing comments, non-idempotent scripts, and subtle query anti-patterns lead to slow queries and confusing codebases. This Skill provides a concrete set of conventions for general SQL work that is not specific to PostGIS spatial data.
Core Features & Use Cases
- Style and Documentation Rules: Enforces lowercase SQL, descriptive comments on every CREATE statement or CTE, consistent formatting, and absolute values (e.g., store "birthday" instead of "age").
- Indexing Guidance: Recommends BRIN indexes for large naturally ordered tables and covering indexes with INCLUDE for cache-table lookups.
- Debugging and Migration Practices: Promotes idempotent SQL files (DROP IF EXISTS + CREATE), paired up/down migrations, meaningful error messages, and avoiding fragile fallbacks like defaulting coordinates to zero.
- SQL Gotcha Rewrites: Rewrites common anti-patterns such as
sum(case when ...) into count() filter (where ...), row_number() = 1 into order by + limit 1, and tags ->> 'key' = 'value' into index-friendly tags @> '{"key": "value"}'.
- Use Case: When reviewing a migration script or refactoring a slow reporting query, apply these rules to produce clean, idempotent, index-aware SQL.
Quick Start
Review my SQL migration file and rewrite it following the sql-programming conventions for formatting, idempotency, and query optimization.