Write correct, readable, and highly performant SQL queries across all major database systems and data warehouse dialects (PostgreSQL, Snowflake, BigQuery, Redshift, Databricks SQL).
Scanned 9/7/2026
Install to Claude Code
npx -y skills add PolyXGO/HeraSpec --skill sql-queries --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Sql Queries?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/polyxgo-sql-queries)More formats (shields.io, HTML) on the badges page.
# Skill: SQL Queries (Cross-Cutting)
## Purpose
Write correct, readable, and highly performant SQL queries across all major database systems and data warehouse dialects (PostgreSQL, Snowflake, BigQuery, Redshift, Databricks SQL).
## When to Use
- When writing complex analytical queries involving CTEs, window functions, and cohort retention calculations.
- When optimizing slow-running SQL queries or translating queries between database dialects.
- When designing data models, schema migrations, and indexing strategies.
## Step-by-Step Process
### Step 1: Analyze Schema & Dialect
- Identify the target database engine (PostgreSQL, BigQuery, Snowflake, etc.).
- Review available table schemas, keys, indexes, and partitioning keys.
### Step 2: Structure Using CTEs
- Break down complex logic into small, readable Common Table Expressions (CTEs) representing logical steps.
### Step 3: Write Dialect-Specific Logic
- Implement date/time arithmetic, string manipulation, JSON/array functions, and window functions using syntax specific to the selected dialect.
### Step 4: Performance Optimization
- Apply database-specific optimization rules:
- PostgreSQL: Use `EXPLAIN ANALYZE`, index columns, prefer `EXISTS` over `IN` for subqueries.
- BigQuery: Minimize scanned bytes, partition on date columns, use `APPROX_COUNT_DISTINCT`.
- Snowflake: Leverage clustering keys, transient tables, and avoid unnecessary warehouse resizing.
### Step 5: Test & Debug
- Verify correct handling of boundary cases (division by zero, null fields, type mismatch casting).
## Required Input
- **Database Engine**: PostgreSQL, BigQuery, Snowflake, etc.
- **Goal/Query Purpose**: What analytical question the query should answer.
- **Table Schema**: Definitions, keys, and partitioning details.
## Expected Output
- **Optimized SQL Code**: Full query code formatted using uppercase keywords and standard alignment.
- **Performance Explanation**: Brief details on partition pruning, indexing, or dialect-specific functions used to speed up the query.
- **Query Flow Explanation**: Explanation of each CTE step for developer readability.
## Tone & Rules
- Write clean, modern SQL using uppercase for keywords (SELECT, FROM, WHERE, etc.).
- Always qualify column names with table aliases when using JOINs.
- Avoid nested subqueries; always prefer Common Table Expressions (CTEs) for readability.
## Available Templates
- None
## Available Scripts
- None
## Examples
See `examples/` directory.
## Links to Other Skills
- **documents**: Use to document database schemas or technical data flow maps.
- **debug**: Use to diagnose and resolve errors returned by SQL execution engines.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!