Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Data Sql Queries

ASecurity

Load before writing or tuning SQL — .sql files, schema DDL, or queries against tables.

60 stars
0 votes
0 copies
0 views
Added 9/28/2026
ai-agentsgosqlperformance

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add ufo-ai/ufo-core --skill data-sql-queries --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Data Sql Queries?

Add the live security badge to your README — it updates automatically with every re-scan.

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

More formats (shields.io, HTML) on the badges page.

Files
SKILL.md
---
name: data-sql-queries
description: Load before writing or tuning SQL — .sql files, schema DDL, or queries against tables.
---
# SQL Queries

Dialect-specific reference and common analytical patterns for data warehouse SQL.

## Dialect Quick Reference

### Date Arithmetic

| Operation | PostgreSQL                      | Snowflake                   | BigQuery                              | Redshift                    | Databricks                 |
| --------- | ------------------------------- | --------------------------- | ------------------------------------- | --------------------------- | -------------------------- |
| Add days  | `+ INTERVAL '7 days'`           | `DATEADD(day, 7, col)`      | `DATE_ADD(col, INTERVAL 7 DAY)`       | `DATEADD(day, 7, col)`      | `DATE_ADD(col, 7)`         |
| Date diff | `end - start`                   | `DATEDIFF(day, start, end)` | `DATE_DIFF(end, start, DAY)`          | `DATEDIFF(day, start, end)` | `DATEDIFF(end, start)`     |
| Truncate  | `DATE_TRUNC('month', col)`      | `DATE_TRUNC('month', col)`  | `DATE_TRUNC(col, MONTH)`              | `DATE_TRUNC('month', col)`  | `DATE_TRUNC('MONTH', col)` |
| Extract   | `EXTRACT(DOW FROM col)` (0=Sun) | `DAYOFWEEK(col)`            | `EXTRACT(DAYOFWEEK FROM col)` (1=Sun) | `DATE_PART('dow', col)`     | `DAYOFWEEK(col)`           |

### Case-Insensitive Matching

| Dialect                         | Pattern                       |
| ------------------------------- | ----------------------------- |
| PostgreSQL, Snowflake, Redshift | `ILIKE '%pattern%'`           |
| BigQuery                        | `LOWER(col) LIKE '%pattern%'` |

### JSON / Semi-Structured Access

| Dialect    | Pattern                                                                         |
| ---------- | ------------------------------------------------------------------------------- |
| PostgreSQL | `data->>'key'` (text), `data#>>'{path,to,key}'` (nested)                        |
| Snowflake  | `col:key::STRING` (VARIANT dot notation), `LATERAL FLATTEN(input => array_col)` |
| BigQuery   | `UNNEST(array_col)`, `struct_col.field_name`                                    |

### Performance Tips by Dialect

- **PostgreSQL**: `EXPLAIN ANALYZE`, `EXISTS` over `IN` for subqueries, partial indexes
- **Snowflake**: Clustering keys (not indexes), filter on cluster columns, `RESULT_SCAN(LAST_QUERY_ID())` to reuse results
- **BigQuery**: Always filter on partition column, `APPROX_COUNT_DISTINCT()` for cardinality, avoid `SELECT *` (billed per byte)
- **Redshift**: DISTKEY for collocated joins, SORTKEY for filters, watch for DS_BCAST/DS_DIST in plan
- **Databricks**: `OPTIMIZE` + `ZORDER`, `CACHE TABLE`, partition by low-cardinality date columns

## Window Functions

```sql
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC)
SUM(revenue) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as running_total
AVG(revenue) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as moving_avg_7d
LAG(value, 1) OVER (PARTITION BY entity ORDER BY date) as prev_value
revenue / SUM(revenue) OVER (PARTITION BY category) as pct_of_category
```

## Common Analytical Patterns

**Deduplication:**

```sql
WITH ranked AS (
    SELECT *, ROW_NUMBER() OVER (PARTITION BY entity_id ORDER BY updated_at DESC) as rn
    FROM source_table
)
SELECT * FROM ranked WHERE rn = 1;
```

**Cohort retention:**

```sql
SELECT
    c.cohort_month,
    COUNT(DISTINCT c.user_id) as cohort_size,
    COUNT(DISTINCT CASE WHEN a.month = c.cohort_month + INTERVAL '1 month' THEN a.user_id END) as month_1
FROM cohorts c LEFT JOIN activity a ON c.user_id = a.user_id
GROUP BY c.cohort_month;
```

**Funnel conversion:**

```sql
SELECT
    SUM(CASE WHEN event = 'view' THEN 1 END) as viewed,
    SUM(CASE WHEN event = 'signup' THEN 1 END) as signed_up,
    ROUND(100.0 * SUM(CASE WHEN event = 'signup' THEN 1 END)
        / NULLIF(SUM(CASE WHEN event = 'view' THEN 1 END), 0), 1) as conv_pct
FROM events WHERE event_date >= CURRENT_DATE - INTERVAL '30 days';
```

## Gotchas

- **BigQuery DATE_TRUNC argument order is reversed** — It's `DATE_TRUNC(col, MONTH)` not `DATE_TRUNC('month', col)`. This silently produces wrong results in some cases instead of erroring.
- **LAST_VALUE needs explicit frame** — Without `ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING`, `LAST_VALUE` uses the default frame that ends at the current row, giving you the current row's value back.
- **COUNT(DISTINCT) in window functions** — Not supported in most dialects. Use a subquery or CTE to pre-aggregate instead.
- **Integer division truncates silently** — `5 / 2 = 2` in most dialects. Cast to float first: `5.0 / 2` or `CAST(x AS FLOAT) / y`.
- **NULL poisons comparisons** — `WHERE col != 'x'` excludes NULLs. Use `WHERE col IS DISTINCT FROM 'x'` (Postgres) or `WHERE COALESCE(col, '') != 'x'` if you want NULLs included.

Attribution

ufo-aiufo-ai
View sourceMore from ufo-ai →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

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 (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Ultra-compressed communication mode that cuts output tokens while keeping technical accuracy. Levels: lite, full, ultra and the wenyan variants. Use for /caveman, "caveman mode", "talk like caveman", "be brief" or "less tokens".

1074701 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

695601 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3351 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

691 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →