Skip to content
Back to skills

Sql Queries

ASecurity

Write correct, readable, and highly performant SQL queries across all major database systems and data warehouse dialects (PostgreSQL, Snowflake, BigQuery, Redshift, Databricks SQL).

  • 26 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 7, 2026
developmentgosqlexpressdatabaseperformance

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 7, 2026

npx -y skills add PolyXGO/HeraSpec --skill sql-queries --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Queries?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sql Queries
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/polyxgo-sql-queries/badge)](https://www.skillsdirectory.com/skills/polyxgo-sql-queries)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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.

Files in this skill

  • skill.md2.6 KB
  • skill.vi.md4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…