
Sql Queries
Write and tune warehouse SQL for product metrics, backends, and ad-hoc analysis without dialect mistakes.
Overview
SQL Queries is an agent skill most often used in Grow (also Build, Operate) that writes and optimizes dialect-correct warehouse SQL for analytics and data-backed features.
Install
npx skills add https://github.com/anthropics/knowledge-work-plugins --skill sql-queriesWhat is this skill?
- Dialect-specific reference for PostgreSQL-family warehouses (Aurora, RDS, Supabase, Neon) plus Snowflake, BigQuery, Data
- Date/time patterns: DATE_TRUNC, INTERVAL arithmetic, EXTRACT, TO_CHAR
- String and pattern ops: ILIKE, regex (~), SPLIT_PART, REGEXP_REPLACE
- JSON and arrays: ->>, #>>, ARRAY_AGG, ANY, containment (@>)
- Performance-oriented guidance embedded alongside syntax examples
- Covers PostgreSQL plus Snowflake, BigQuery, Databricks, and related warehouse dialects per skill description
- Includes dedicated PostgreSQL reference blocks for date/time, strings, JSON, and arrays
Adoption & trust: 2.5k installs on skills.sh; 19.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need trustworthy SQL across Postgres, Snowflake, BigQuery, or Databricks but keep hitting wrong date functions, slow plans, or dialect drift.
Who is it for?
Indie SaaS founders querying Postgres/Supabase/Neon or a cloud warehouse for funnels, revenue, and operational rollups.
Skip if: Teams that only need ORM migrations with zero raw SQL, or fully managed no-SQL analytics with no custom queries.
When should I use this skill?
Write queries, optimize slow SQL, translate between dialects, or build complex analytical queries with CTEs, window functions, or aggregations.
What do I get? / Deliverables
You get dialect-aware query patterns—CTEs, windows, aggregations, and performance notes—ready to run or paste into your repo and BI tools.
- Dialect-correct SELECT queries with CTEs, windows, or aggregations
- Optimized or rewritten SQL with dialect-specific date, string, and JSON patterns
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Analytical querying is the canonical grow/analytics job, even though the same patterns appear when building data-backed features. Solo builders reach for this skill when turning events, revenue, or ops data into correct aggregations, CTEs, and window-function reports.
Where it fits
Draft aggregate SQL for a revenue API backed by Postgres before shipping the endpoint.
Build a monthly active-user CTE chain with correct DATE_TRUNC for a Metabase dashboard.
Rewrite a nightly job query that regressed after moving from RDS to BigQuery syntax.
How it compares
Procedural SQL reference for agents, not a hosted query runner or schema migration CLI.
Common Questions / FAQ
Who is sql-queries for?
Solo and indie builders who write their own analytics SQL across PostgreSQL-family databases and major cloud warehouses.
When should I use sql-queries?
During grow analytics for dashboards and KPIs, during build when adding reporting endpoints or ETL SQL, and during operate when tuning slow production queries or translating dialects.
Is sql-queries safe to install?
Review the Security Audits panel on this Prism page and the upstream Anthropics plugin repo before enabling it in agents with broad filesystem or network access.
SKILL.md
READMESKILL.md - Sql Queries
# SQL Queries Skill Write correct, performant, readable SQL across all major data warehouse dialects. ## Dialect-Specific Reference ### PostgreSQL (including Aurora, RDS, Supabase, Neon) **Date/time:** ```sql -- Current date/time CURRENT_DATE, CURRENT_TIMESTAMP, NOW() -- Date arithmetic date_column + INTERVAL '7 days' date_column - INTERVAL '1 month' -- Truncate to period DATE_TRUNC('month', created_at) -- Extract parts EXTRACT(YEAR FROM created_at) EXTRACT(DOW FROM created_at) -- 0=Sunday -- Format TO_CHAR(created_at, 'YYYY-MM-DD') ``` **String functions:** ```sql -- Concatenation first_name || ' ' || last_name CONCAT(first_name, ' ', last_name) -- Pattern matching column ILIKE '%pattern%' -- case-insensitive column ~ '^regex_pattern$' -- regex -- String manipulation LEFT(str, n), RIGHT(str, n) SPLIT_PART(str, delimiter, position) REGEXP_REPLACE(str, pattern, replacement) ``` **Arrays and JSON:** ```sql -- JSON access data->>'key' -- text data->'nested'->'key' -- json data#>>'{path,to,key}' -- nested text -- Array operations ARRAY_AGG(column) ANY(array_column) array_column @> ARRAY['value'] ``` **Performance tips:** - Use `EXPLAIN ANALYZE` to profile queries - Create indexes on frequently filtered/joined columns - Use `EXISTS` over `IN` for correlated subqueries - Partial indexes for common filter conditions - Use connection pooling for concurrent access --- ### Snowflake **Date/time:** ```sql -- Current date/time CURRENT_DATE(), CURRENT_TIMESTAMP(), SYSDATE() -- Date arithmetic DATEADD(day, 7, date_column) DATEDIFF(day, start_date, end_date) -- Truncate to period DATE_TRUNC('month', created_at) -- Extract parts YEAR(created_at), MONTH(created_at), DAY(created_at) DAYOFWEEK(created_at) -- Format TO_CHAR(created_at, 'YYYY-MM-DD') ``` **String functions:** ```sql -- Case-insensitive by default (depends on collation) column ILIKE '%pattern%' REGEXP_LIKE(column, 'pattern') -- Parse JSON column:key::string -- dot notation for VARIANT PARSE_JSON('{"key": "value"}') GET_PATH(variant_col, 'path.to.key') -- Flatten arrays/objects SELECT f.value FROM table, LATERAL FLATTEN(input => array_col) f ``` **Semi-structured data:** ```sql -- VARIANT type access data:customer:name::STRING data:items[0]:price::NUMBER -- Flatten nested structures SELECT t.id, item.value:name::STRING as item_name, item.value:qty::NUMBER as quantity FROM my_table t, LATERAL FLATTEN(input => t.data:items) item ``` **Performance tips:** - Use clustering keys on large tables (not traditional indexes) - Filter on clustering key columns for partition pruning - Set appropriate warehouse size for query complexity - Use `RESULT_SCAN(LAST_QUERY_ID())` to avoid re-running expensive queries - Use transient tables for staging/temp data --- ### BigQuery (Google Cloud) **Date/time:** ```sql -- Current date/time CURRENT_DATE(), CURRENT_TIMESTAMP() -- Date arithmetic DATE_ADD(date_column, INTERVAL 7 DAY) DATE_SUB(date_column, INTERVAL 1 MONTH) DATE_DIFF(end_date, start_date, DAY) TIMESTAMP_DIFF(end_ts, start_ts, HOUR) -- Truncate to period DATE_TRUNC(created_at, MONTH) TIMESTAMP_TRUNC(created_at, HOUR) -- Extract parts EXTRACT(YEAR FROM created_at) EXTRACT(DAYOFWEEK FROM created_at) -- 1=Sunday -- Format FORMAT_DATE('%Y-%m-%d', date_column) FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', ts_column) ``` **String functions:** ```sql -- No ILIKE, use LOWER() LOWER(column) LIKE '%pattern%' REGEXP_CONTAINS(column, r'pattern') REGEXP_EXTRACT(column, r'pattern') -- String manipulation SPLIT(str, delimiter) -- returns ARRAY ARRAY_TO_STRING(array, delimiter) ``` **Arrays and structs:** ```sql -- Array