sql-queries

Write and optimize SQL queries across Snowflake, BigQuery, PostgreSQL, Redshift, and Databricks dialects.

1|Updated Mar 2, 2026
Ready to run
npx skills add https://github.com/monthop-gmail/botforge --skill sql-queries-monthop-gmail
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: sql-queries
Source: https://github.com/monthop-gmail/botforge/tree/main/templates/bot-service-adkcode/server/plugins/data/skills/sql-queries
Command: npx skills add https://github.com/monthop-gmail/botforge --skill sql-queries-monthop-gmail

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct SQL across different data warehouses is error-prone because each dialect has distinct syntax for dates, strings, JSON, and performance tuning. This Skill provides dialect-specific syntax references and proven query patterns so you avoid syntax errors, slow queries, and costly full-table scans. ## Core Features & Use Cases - Dialect-Specific Syntax Reference: Covers PostgreSQL, Snowflake, BigQuery, Redshift, and Databricks with date/time functions, string manipulation, JSON access, and performance tips for each. - Analytical Query Patterns: Ready-to-adapt templates for window functions, CTEs, cohort retention, funnel analysis, and deduplication. - Error Debugging Guidance: Systematic troubleshooting for syntax errors, type mismatches, division by zero, and GROUP BY issues. - Use Case: You need a monthly cohort retention report on BigQuery. Use this Skill to get the correct DATE_TRUNC and INTERVAL syntax, then adapt the cohort retention template to your schema. ## Quick Start Ask the AI to write a funnel analysis query in BigQuery that tracks users from page view through first purchase over the last 30 days.

Frequently Asked Questions about sql-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a cohort retention query in SQL?▼

Build a cohorts CTE assigning each user to a cohort month via DATE_TRUNC on their first activity date, then join activity months and count distinct users per period offset. The Skill provides a complete template adaptable to PostgreSQL, BigQuery, or Snowflake.

How to optimize slow SQL queries in BigQuery?▼

Filter on partition columns to reduce bytes scanned, use clustering for frequently filtered columns, and avoid SELECT * since billing is per-byte. Use APPROX_COUNT_DISTINCT for large cardinality estimates and dry-run queries to preview cost.

What is the difference between Snowflake and BigQuery date functions?▼

Snowflake uses DATEADD(day, 7, col) and DATEDIFF(day, start, end), while BigQuery uses DATE_ADD(col, INTERVAL 7 DAY) and DATE_DIFF(end, start, DAY). Both support DATE_TRUNC but with reversed argument order.

Does PostgreSQL support case-insensitive pattern matching?▼

Yes, PostgreSQL supports ILIKE for case-insensitive matching and the ~ operator for regex. BigQuery lacks ILIKE, so use LOWER(column) LIKE or REGEXP_CONTAINS instead.

Why does my SQL query fail with a division by zero error?▼

Division by zero occurs when a denominator column contains zero values. Wrap denominators with NULLIF(denominator, 0) to return NULL instead of erroring, or use BigQuery's SAFE_DIVIDE function.

How do I deduplicate rows keeping the most recent record?▼

Use ROW_NUMBER() OVER (PARTITION BY entity_id ORDER BY updated_at DESC) in a CTE, then filter where the row number equals 1. This pattern works across all major warehouse dialects.