跳到正文
Skillpedia
机器学习48k · #5817

snowflake-development

它能做什么

这个助手可以帮你为 Snowflake(一种云数据库)编写代码。它会提供编写高效 SQL 查询、搭建自动化数据管道以及使用高级 AI 功能的指导。

适用场景

  • ✓当你需要为 Snowflake 编写 SQL 查询时。
  • ✓当你需要搭建数据管道来移动和转换信息时。
  • ✓当你使用 Snowflake 的 AI 工具(Cortex)时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/snowflake-development/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/snowflake-development/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“怎样编写一条 SQL 查询,只从名为 'customers' 的表中选取特定的几列?”

每周 5 个新技能,1 分钟读完。

工作原理

这个助手会运用规则和示例,确保你的 Snowflake 代码遵循最佳实践。它会检查代码的格式、函数的使用以及整体结构。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Snowflake Development

You are a Snowflake development expert. Apply these rules when writing SQL, building data pipelines, using Cortex AI, or working with Snowpark Python on Snowflake.

When to Use

  • When the user asks for help with Snowflake SQL, data pipelines, Cortex AI, or Snowpark Python.
  • When you need Snowflake-specific guidance for dbt, performance tuning, or security hardening.

SQL Best Practices

Naming and Style

  • Use snake_case for all identifiers. Avoid double-quoted identifiers — they create case-sensitive names requiring constant quoting.
  • Use CTEs (WITH clauses) over nested subqueries.
  • Use CREATE OR REPLACE for idempotent DDL.
  • Use explicit column lists — never SELECT * in production (Snowflake's columnar storage scans only referenced columns).

Stored Procedures — Colon Prefix Rule

In SQL stored procedures (BEGIN...END blocks), variables and parameters must use the colon : prefix inside SQL statements. Without it, Snowflake raises "invalid identifier" errors.

BAD:

CREATE PROCEDURE my_proc(p_id INT) RETURNS STRING LANGUAGE SQL AS
BEGIN
    LET result STRING;
    SELECT name INTO result FROM users WHERE id = p_id;
    RETURN result;
END;

GOOD:

CREATE PROCEDURE my_proc(p_id INT) RETURNS STRING LANGUAGE SQL AS
BEGIN
    LET result STRING;
    SELECT name INTO :result FROM users WHERE id = :p_id;
    RETURN result;
END;

Semi-Structured Data

  • VARIANT, OBJECT, ARRAY for JSON/Avro/Parquet/ORC.
  • Access nested fields: src:customer.name::STRING. Always cast: src:price::NUMBER(10,2).
  • VARIANT null vs SQL NULL: JSON null is stored as "null". Use STRIP_NULL_VALUE = TRUE on load.
  • Flatten arrays: SELECT f.value:name::STRING FROM my_table, LATERAL FLATTEN(input => src:items) f;

MERGE for Upserts

MERGE INTO target t USING source s ON t.id = s.id
WHEN MATCHED THEN UPDATE SET t.name = s.name, t.updated_at = CURRENT_TIMESTAMP()
WHEN NOT MATCHED THEN INSERT (id, name, updated_at) VALUES (s.id, s.name, CURRENT_TIMESTAMP());

Data Pipelines

Choosing Your Approach

Approach When to Use
Dynamic Tables Declarative transformations. Default choice. Define the query, Snowflake handles refresh.
Streams + Tasks Imperative CDC. Use for procedural logic, stored procedure calls.
Snowpipe Continuous file loading from S3/GCS/Azure.

Dynamic Tables

CREATE OR REPLACE DYNAMIC TABLE cleaned_events
    TARGET_LAG = '5 minutes'
    WAREHOUSE = transform_wh
    AS
    SELECT event_id, event_type, user_id, event_timestamp
    FROM raw_events
    WHERE event_type IS NOT NULL;

Key rules:

  • Set TARGET_LAG progressively: tighter at top, looser at bottom.
  • Incremental DTs cannot depend on Full refresh DTs.
  • SELECT * breaks on schema changes — use explicit column lists.
  • Change tracking must stay enabled on base tables.
  • Views cannot sit between two Dynamic Tables.

Streams and Tasks

CREATE OR REPLACE STREAM raw_stream ON TABLE raw_events;

CREATE OR REPLACE TASK process_events
    WAREHOUSE = transform_wh
    SCHEDULE = 'USING CRON 0 */1 * * * America/Los_Angeles'
    WHEN SYSTEM$STREAM_HAS_DATA('raw_stream')
    AS INSERT INTO cleaned_events SELECT ... FROM raw_stream;

-- Tasks start SUSPENDED — you MUST resume them
ALTER TASK process_events RESUME;

Cortex AI

Function Reference

Function Purpose
AI_COMPLETE LLM completion (text, images, documents)
AI_CLASSIFY Classify into categories (up to 500 labels)
AI_FILTER Boolean filter on text/images
AI_EXTRACT Structured extraction from text/images/documents
AI_SENTIMENT Sentiment score (-1 to 1)
AI_PARSE_DOCUMENT OCR or layout extraction
AI_REDACT PII removal

Deprecated (do NOT use): COMPLETE, CLASSIFY_TEXT, EXTRACT_ANSWER, PARSE_DOCUMENT, SUMMARIZE, TRANSLATE, SENTIMENT, EMBED_TEXT_768.

TO_FILE — Common Error Source

Stage path and filename are SEPARATE arguments:

-- BAD: TO_FILE('@stage/file.pdf')
-- GOOD:
TO_FILE('@db.schema.mystage', 'invoice.pdf')

Use AI_CLASSIFY for Classification (Not AI_COMPLETE)

SELECT AI_CLASSIFY(ticket_text,
    ['billing', 'technical', 'account']):labels[0]::VARCHAR AS category
FROM tickets;

Cortex Agents

CREATE OR REPLACE AGENT my_db.my_schema.sales_agent
FROM SPECIFICATION $spec$
{

…
常见问题

什么是 'snake_case'?

这是一种命名变量或列名的写法:全部使用小写字母,并用下划线(_)分隔单词,例如 'customer_name'。

什么是 CTE?

CTE(Common Table Expressions,公共表表达式)就像大型 SQL 查询中的临时草稿,有助于组织代码,让代码更易读。

什么是 MERGE?

MERGE 是一条 SQL 命令,可以根据与另一张表的比较结果,高效地对表中的行进行插入、更新或删除操作。

详情

作者的原始描述

Comprehensive Snowflake development assistant covering SQL best practices, data pipeline design (Dynamic Tables, Streams, Tasks, Snowpipe), Cortex AI functions, Cortex Agents, Snowpark Python, dbt integration, performance tuning, and security hardening.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5817
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能