motherduck-query

Generate DuckDB SQL queries for analytics against MotherDuck databases.

53|3|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/motherduckdb/agent-skills --skill motherduck-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: motherduck-query
Source: https://github.com/motherduckdb/agent-skills/tree/main/plugins/motherduck-skills-claude/skills/motherduck-query
Command: npx skills add https://github.com/motherduckdb/agent-skills --skill motherduck-query

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you execute correct, production-ready analytical SQL against MotherDuck by turning ambiguous, PostgreSQL-shaped queries into DuckDB-native queries with predictable results and safer execution semantics.

Core Features & Use Cases

  • DuckDB SQL-first guidance: Produces DuckDB-native query patterns (CTEs, window functions with QUALIFY, GROUP BY ALL) instead of PostgreSQL-style SQL.
  • Correctness and performance guardrails: Encourages fully qualified table names, explicit result grain, early filtering/aggregation, and plan/shape checks to avoid inefficient rescans and unintended sorts.
  • Safe operations posture: Treats DDL/DML and lifecycle/recovery commands as writes and clarifies when MCP write-capable operations should be used only with explicit user confirmation.

Quick Start

Use motherduck-query to generate a DuckDB SQL query that returns the top 20 customers by total completed order amount for a specified date range using fully qualified table names.

Frequently Asked Questions about motherduck-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write DuckDB SQL for analytics queries in MotherDuck instead of PostgreSQL?

To write DuckDB SQL for MotherDuck analytics queries, use DuckDB-native patterns like CTEs, window functions with QUALIFY, and GROUP BY ALL rather than PostgreSQL syntax. Ensure fully qualified table names and explicit result grains to maintain correctness and predictable execution.

What is the QUALIFY clause used for in DuckDB SQL window functions?

The QUALIFY clause in DuckDB SQL filters results of window functions directly within the query. It enables window-function filtering to enforce correct result grains without wrapping the entire query in a subquery, simplifying analytics logic and improving performance.

How do I structure complex data exploration queries using CTEs in DuckDB?

Structure complex data exploration queries in DuckDB using CTEs to break down transformations into sequential, readable steps. This CTE-based structuring clarifies explicit result grains and applies early filtering and aggregation to avoid inefficient rescans during analytics processing.

Does MotherDuck support PostgreSQL-style SQL syntax for aggregations and transformations?

MotherDuck does not support PostgreSQL-style SQL syntax for aggregations and transformations. It requires DuckDB SQL syntax with fully qualified table identifiers, utilizing DuckDB-native patterns like GROUP BY ALL and QUALIFY to ensure correct execution semantics and safer operations.

Are DDL and DML commands treated as safe read operations in DuckDB SQL?

DDL, DML, and lifecycle or recovery commands are treated as write operations in DuckDB SQL, not safe read operations. These safety-aware writes should only be executed using MCP write-capable operations with explicit user confirmation to prevent unintended modifications.

What's the best way to optimize performance tuning for DuckDB SQL aggregations?

Optimize performance tuning for DuckDB SQL aggregations by applying early filtering, explicit result grain definitions, and plan or shape checks. These performance-aware patterns prevent unintended sorts and inefficient rescans during analytics queries against MotherDuck databases.