motherduck-query
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQuery 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连接
motherduck-connect - 通过确定目标数据库和表
motherduck-explore
Default Posture
默认准则
- Write DuckDB SQL, not PostgreSQL SQL, even when using the PG endpoint.
- Always use fully qualified names.
"database"."schema"."table" - 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, recovery commands such asDETACH,CREATE SNAPSHOT,ALTER DATABASE ... SET SNAPSHOT, and lifecycle commands such asUNDROP DATABASEas writes. Use MCPSHUTDOWNonly when the user explicitly asks for the change and confirms it.query_rw - Tag long-lived integrations with when the connection path supports it.
custom_user_agent
- 编写DuckDB SQL,而非PostgreSQL SQL,即使使用PG端点时也应如此。
- 始终使用完全限定的名称。
"database"."schema"."table" - 保留每个结果集的预期粒度;在优化或物化查询前说明该粒度。
- 尽早过滤、尽早聚合,对于重复读取优先使用服务表或汇总表。
- 保持SQL清晰明了、多行书写,并明确说明粒度、过滤条件和输出结构。
- 将DDL、DML、、
ATTACH、恢复命令(如DETACH、CREATE SNAPSHOT、ALTER DATABASE ... SET SNAPSHOT)以及生命周期命令(如UNDROP DATABASE)视为写入操作。仅当用户明确要求更改并确认后,才可使用MCPSHUTDOWN。query_rw - 当连接路径支持时,为长期运行的集成添加标签。
custom_user_agent
Workflow
工作流程
- Confirm the actual tables, columns, and grain before writing SQL.
- Write the query in SQL first, then wrap it in Python or TypeScript only if needed.
- Use CTEs and DuckDB-native patterns such as ,
GROUP BY ALL, andQUALIFY.arg_max - Check the plan, row count, and shape for pushdown, unnecessary sorts, or repeated raw rescans.
- Materialize expensive repeated queries into serving tables or light views when warranted.
- 在编写SQL前,确认实际的表、列和粒度。
- 先以SQL编写查询,仅在必要时再用Python或TypeScript封装。
- 使用CTE和DuckDB原生模式,如、
GROUP BY ALL和QUALIFY。arg_max - 检查执行计划、行数和结构,查看是否存在下推、不必要的排序或重复的原始重扫描。
- 当需要时,将耗时的重复查询物化为服务表或轻量视图。
Open Next
后续参考
- for DuckDB query patterns, exploration SQL, performance rules, common analytical shapes, and common mistakes
references/QUERY_PLAYBOOK.md
- 参考获取DuckDB查询模式、探索性SQL、性能规则、常见分析结构以及常见错误相关内容
references/QUERY_PLAYBOOK.md
Related Skills
相关技能
- for session setup
motherduck-connect - for syntax and function reference
motherduck-duckdb-sql - for understanding the source schema before writing queries
motherduck-explore
- :用于会话设置
motherduck-connect - :用于语法和函数参考
motherduck-duckdb-sql - :用于在编写查询前了解源模式
motherduck-explore