SQL Queries

Official Anthropic skill for correct, performant SQL across multiple database dialects.

SQL Queries is an official skill from Anthropic’s knowledge-work-plugins repository. Its direct primary source is https://github.com/anthropics/knowledge-work-plugins/tree/main/data/skills/sql-queries. According to the provider, the skill helps Claude write correct, readable, and performant SQL for major database and data-warehouse dialects. The source covers PostgreSQL, Snowflake, BigQuery, Databricks, and Redshift among others. The skill is a text-based knowledge and workflow instruction, not a database driver, hosting service, query proxy, or guarantee that an unreviewed query is functionally or economically safe.

Purpose and professional boundary

The skill is intended for writing new queries, optimizing slow SQL, translating between dialects, and building complex analytical queries with common table expressions, window functions, or aggregations. The source combines syntax knowledge with practical advice about data modeling, execution, and performance. Anyone designing a query must still inspect the actual schema, data types, permissions, null semantics, time zones, and expected results. A syntactically valid statement can produce incorrect business metrics, multiply rows unexpectedly, or create unplanned cost and load.

Dialects and time logic

For PostgreSQL, the primary source covers expressions such as CURRENT_DATE, CURRENT_TIMESTAMP, interval arithmetic, DATE_TRUNC, EXTRACT, TO_CHAR, ILIKE, regular expressions, string functions, JSON access, and array operations. Snowflake uses different date-arithmetic forms and supports VARIANT access plus LATERAL FLATTEN for semi-structured data. BigQuery uses functions including DATE_ADD, DATE_DIFF, TIMESTAMP_DIFF, LOWER, REGEXP_CONTAINS, UNNEST, and STRUCT fields. Databricks SQL and Redshift each have their own function and optimization models. The skill helps identify these differences, but it does not replace the version-specific documentation of the system being used.

Performance and responsible execution

The recommendations vary by platform. In PostgreSQL, EXPLAIN ANALYZE, suitable indexes, partial indexes, EXISTS, and connection pooling may matter. Snowflake relies more on clustering, partition pruning, an appropriate warehouse size, and RESULT_SCAN. According to the source, BigQuery benefits from filtering partition columns, clustering, APPROX_COUNT_DISTINCT, parameterized scripts, and checking cost with a dry run. Redshift considers distribution keys, sort keys, EXPLAIN, data movement, ANALYZE, and VACUUM. These are starting points rather than universal rules. Test first with a bounded, non-sensitive dataset, inspect the execution plan, and obtain human approval before running expensive or write-capable statements.

Dialects and Patterns

The skill covers PostgreSQL, Snowflake, BigQuery, Redshift and Databricks SQL, each with its own syntax. PostgreSQL uses DATE_TRUNC and ILIKE, Snowflake uses LATERAL FLATTEN for nested data, BigQuery bills by bytes scanned, Redshift works with distribution and sort keys instead of indexes, and Databricks offers time travel with TIMESTAMP AS OF. Recurring patterns are cohort analysis, funnel analysis and deduplication. Optimization includes filtering on partition columns, avoiding SELECT * in cost-conscious queries and EXPLAIN ANALYZE for profiling.

E-E-A-T, security, and limitations

This entry is grounded in the official Anthropic source path and Anthropic’s official Claude Code documentation for skills. Provider statements are explicitly identified as according to the provider. SQL can expose confidential data, lock tables, consume resources, or modify records. Avoid unparameterized user input, review permissions according to least privilege, and separate read access from write access. Do not run destructive changes, deletions, or migrations until the target, transaction, backup and recovery plan, and authorization are clear. Never store passwords, tokens, private keys, or real customer data in prompts or skill text. A local skill file does not automatically mean local model processing; a connected client may transmit inputs and results to its model provider. Official dialect documentation remains authoritative for current syntax and platform behavior.

Installation instructions

This guide complements Anthropic’s official SQL Queries source. It describes a controlled workflow and does not replace your database documentation or approval by the responsible database and domain professionals.

Clarify the task and dialect

Start by defining the business question, required grain, time window, and expected output. Then identify the exact system and version. PostgreSQL, Snowflake, BigQuery, Databricks, and Redshift differ in date functions, JSON, arrays, regular expressions, partitioning, and execution models. A dialect translation is only reliable after the schema, data types, and edge cases are known.

Step 1: Start with a safe design

Begin with a read-only design and bound the data volume when the platform supports it. Use parameters instead of concatenated user input. Name CTEs and calculated columns clearly, document join assumptions, and check whether NULL values, duplicates, and time zones change the metric. Compare sample results with a trusted reference before widening the scope.

Review the plan and resources

Inspect the execution plan before starting a large query. Check partition filters, possible full scans, join cardinality, sorting, spilling, clustering, and data movement. In BigQuery, perform a cost estimate or dry run first. In other systems, EXPLAIN, EXPLAIN ANALYZE, or platform-specific tools may be appropriate. A faster query is not automatically correct if it omits rows.

Limit write access and data exposure

Separate analytical, development, and production roles. Test with anonymized or synthetic data, and never place secrets in skill text, prompts, logs, or sample queries. Before INSERT, UPDATE, DELETE, DDL, or migrations, clarify the target, predicate, transaction, backup, and recovery plan. Do not execute an irreversible change merely because a model suggested it.

Obtain professional sign-off

Check figures against known control totals, periods, samples, and the definition of the metric. Have an authorized person review changes and record the dialect, version, assumptions, and execution time. Remember that a connected client may transmit data and results to a model provider. Keep the official platform documentation as the reference when functions or provider terms change.

Free
Provider
Anthropic
Last reviewed
09.09.2026

Repository and documentation

Categories

Compatible with

Claude Code