motherduck-query

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Query MotherDuck

查询MotherDuck

Use this skill when executing SQL queries for analytics, aggregations, transformations, or data exploration against MotherDuck databases.
当你需要针对MotherDuck数据库执行SQL查询以进行数据分析、聚合、转换或数据探索时,请使用本技能。

Prerequisites

前置条件

  • MotherDuck connection established via
    motherduck-connect
  • Target database and tables identified via
    motherduck-explore
  • 通过
    motherduck-connect
    建立MotherDuck连接
  • 通过
    motherduck-explore
    确定目标数据库和表

Default Posture

默认准则

  • Write DuckDB SQL, not PostgreSQL SQL, even when using the PG endpoint.
  • Always use fully qualified
    "database"."schema"."table"
    names.
  • Preserve the intended grain of every result set; state the grain before optimizing or materializing a query.
  • Filter early, aggregate early, and prefer serving tables or summaries for repeated reads.
  • Keep SQL obvious, multi-line, and explicit about grain, filters, and output shape.
  • Treat DDL, DML,
    ATTACH
    ,
    DETACH
    , recovery commands such as
    CREATE SNAPSHOT
    ,
    ALTER DATABASE ... SET SNAPSHOT
    ,
    UNDROP DATABASE
    , and lifecycle commands such as
    SHUTDOWN
    as writes. Use MCP
    query_rw
    only when the user explicitly asks for the change and confirms it.
  • Tag long-lived integrations with
    custom_user_agent
    when the connection path supports it.
  • 编写DuckDB SQL,而非PostgreSQL SQL,即使使用PG端点时也应如此。
  • 始终使用完全限定的
    "database"."schema"."table"
    名称。
  • 保留每个结果集的预期粒度;在优化或物化查询前说明该粒度。
  • 尽早过滤、尽早聚合,对于重复读取优先使用服务表或汇总表。
  • 保持SQL清晰明了、多行书写,并明确说明粒度、过滤条件和输出结构。
  • 将DDL、DML、
    ATTACH
    DETACH
    、恢复命令(如
    CREATE SNAPSHOT
    ALTER DATABASE ... SET SNAPSHOT
    UNDROP DATABASE
    )以及生命周期命令(如
    SHUTDOWN
    )视为写入操作。仅当用户明确要求更改并确认后,才可使用MCP
    query_rw
  • 当连接路径支持时,为长期运行的集成添加
    custom_user_agent
    标签。

Workflow

工作流程

  1. Confirm the actual tables, columns, and grain before writing SQL.
  2. Write the query in SQL first, then wrap it in Python or TypeScript only if needed.
  3. Use CTEs and DuckDB-native patterns such as
    GROUP BY ALL
    ,
    QUALIFY
    , and
    arg_max
    .
  4. Check the plan, row count, and shape for pushdown, unnecessary sorts, or repeated raw rescans.
  5. Materialize expensive repeated queries into serving tables or light views when warranted.
  1. 在编写SQL前,确认实际的表、列和粒度。
  2. 先以SQL编写查询,仅在必要时再用Python或TypeScript封装。
  3. 使用CTE和DuckDB原生模式,如
    GROUP BY ALL
    QUALIFY
    arg_max
  4. 检查执行计划、行数和结构,查看是否存在下推、不必要的排序或重复的原始重扫描。
  5. 当需要时,将耗时的重复查询物化为服务表或轻量视图。

Open Next

后续参考

  • references/QUERY_PLAYBOOK.md
    for DuckDB query patterns, exploration SQL, performance rules, common analytical shapes, and common mistakes
  • 参考
    references/QUERY_PLAYBOOK.md
    获取DuckDB查询模式、探索性SQL、性能规则、常见分析结构以及常见错误相关内容

Related Skills

相关技能

  • motherduck-connect
    for session setup
  • motherduck-duckdb-sql
    for syntax and function reference
  • motherduck-explore
    for understanding the source schema before writing queries
  • motherduck-connect
    :用于会话设置
  • motherduck-duckdb-sql
    :用于语法和函数参考
  • motherduck-explore
    :用于在编写查询前了解源模式