Skip to main content

Cookbook

Browse runnable cookbook entries and flight plans for common MotherDuck workflows. Each page includes setup instructions and source code in the motherduck-cookbook repository.

categoryfeaturestags

52 of 52 results

Monitor MotherDuck in Datadog

I want to monitor my MotherDuck organization from Datadog: query throughput, latency, errors, spills, running queries, active users, storage, tokens, Flight runs, Dive usage and Guides on a dashboard with alerts. Help me adapt the "Monitor MotherDuck in Datadog" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/motherduck-datadog

Export a Dive to PDF and Deliver It

I want a scheduled PDF or PNG of one of my MotherDuck Dives rendered and delivered to my team over Slack, Microsoft Teams, or email, without anyone clicking anything. Help me adapt the "Export a Dive to PDF and Deliver It" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dive-export

Transform Databricks Iceberg on MotherDuck, Write Straight Back to Iceberg

I keep my lakehouse in Databricks Unity Catalog and want a scheduled Flight that reads an Iceberg table, transforms it on MotherDuck, and writes the result straight back to Iceberg without staging a copy in MotherDuck. Help me adapt the "Transform Databricks Iceberg on MotherDuck, Write Straight Back to Iceberg" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-iceberg-databricks-direct

Transform Databricks Iceberg via a MotherDuck Staging Table

I keep my lakehouse in Databricks Unity Catalog and want a scheduled Flight that reads an Iceberg table, transforms it into a MotherDuck table I can query and share, and then publishes that table back to Iceberg. Help me adapt the "Transform Databricks Iceberg via a MotherDuck Staging Table" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-iceberg-databricks-stage

Build a Common Crawl Web Graph Time Series

I want a reproducible Common Crawl web-graph time series for a fixed set of hosted platforms, with host-level rows and a domain-file count check. Help me adapt the "Build a Common Crawl Web Graph Time Series" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-commoncrawl-web-graph

Copy a Postgres Table into MotherDuck With the DuckDB ADBC Extension

I want a simple Flight that copies a table from a Postgres database into MotherDuck through the DuckDB ADBC extension and an ADBC driver installed with dbc. Help me adapt the "Copy a Postgres Table into MotherDuck With the DuckDB ADBC Extension" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-adbc-ingest

Give Every Dive Your Brand Style With a Guide

I want every Dive my team builds to follow our brand palette, number formatting, and layout rules, published once org-wide rather than restated each session. Help me adapt the "Give Every Dive Your Brand Style With a Guide" MotherDuck recipe to our conventions, using it as a guide: https://motherduck.com/docs/cookbook/dive-style-guide

Ingest Shopify Orders and Products as a Flight

I want my Shopify orders, customers, and products loaded into MotherDuck on a schedule, without storing a long-lived Admin API token anywhere. Help me adapt the "Ingest Shopify Orders and Products as a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-shopify-ingest

Incrementally ingest GA4 BigQuery exports into MotherDuck

I want to incrementally ingest GA4's BigQuery export into MotherDuck with a scheduled Flight and a safe late-arrival overlap. Help me adapt the "Incrementally ingest GA4 BigQuery exports into MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-ga4-bigquery-ingest

Load a Local Excel File into MotherDuck

I have an Excel .xlsx file on my machine and I want to load a sheet into a MotherDuck table with the DuckDB Python client and read_xlsx, without converting to CSV. Help me adapt the "Load a Local Excel File into MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/excel-local-ingest

Ingest an Excel Workbook from S3 on a Schedule

Excel workbooks land in my S3 bucket and I want a scheduled Flight that loads a sheet into a MotherDuck table with read_xlsx, full-refresh each run. Help me adapt the "Ingest an Excel Workbook from S3 on a Schedule" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-excel-s3-ingest

Copy AWS S3 Tables (Iceberg) into MotherDuck With a Flight

I have tables in an AWS S3 Tables Iceberg bucket and I want to copy them into MotherDuck as native tables, on a schedule, so my queries stop re-scanning Iceberg every time. I need to choose which namespaces and tables get copied, and I want a re-run to just replace the data. Help me adapt the "Copy AWS S3 Tables (Iceberg) into MotherDuck With a Flight" recipe to my own bucket and use case, using it as a starting point.

Run a dbt Project as a Flight via GitHub Archive

I want one deployed Flight that builds my dbt project on MotherDuck on a schedule and keeps a queryable history of build and test health — per-model status, timing, and test pass/fail over time — instead of just running dbt and losing the results. Help me adapt the "Run a dbt Project as a Flight via GitHub Archive" recipe to my own dbt repo and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dbt-build-gh-archive

Run a dbt Project as a Flight via git clone

I want one deployed Flight that git-clones my dbt project at run time, builds it on MotherDuck on a schedule, and keeps a queryable history of build and test health tagged with the exact commit SHA it built. Help me adapt the "Run a dbt Project as a Flight via git clone" recipe to my own dbt repo and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dbt-build-git

Re-Sort a Table for Fast Selective Queries

This flight will sort a MotherDuck table in full or in part. The purpose is to improve read performance to use DuckDB's min/max indexes (also called zonemaps) (research here to learn more: https://duckdb.org/2025/05/14/sorting-for-fast-selective-queries). The flight should take as input: table_to_order, order_by_clause, where_clause. The flight should first validate the inputs do not permit SQL injection. Create dummy SQL statements and use the DuckDB tokenizer (available as a table function) to try to tokenize each input. The tokenizer should only find a single statement, and it should be a select statement. For example, the dummy statement for table_to_order would be `select * from table_to_order`, for the order by it would be `select * from table_to_order order by order_by_clause`. I want the Flight to be flexible enough to detect if there is an `ORDER BY` as the initial few tokens (with any whitespace around them) or `WHERE` as the first few tokens in the where_clause so that the user can either specify them or not and it will still work. Make sure the check is case insensitive as well. Once inputs are validated, the overall task of the flight is to: Begin a transaction, create a table (a real table, not a temporary table) that is the name of the table_to_order but with a random uuid appended to it using the SQL pseudo code of `create or replace table table_to_order_[random_uuid] as select * from table_to_order where where_clause`, then delete the data from the original table with `delete from table_to_order where where_clause`, then re-insert the data but sorted with `insert into table_to_order select * from table_to_order_[random_uuid] order by order_by_clause`, commit the transaction.

Build an automated AI data analysis agent with Flights

I want to build my own data-analysis agent and run it on a schedule in MotherDuck: it discovers the entities to cover, fans out one agent each, explores my warehouse with read-only SQL, and writes a ranked "notable things" brief. Help me adapt the "Build an automated AI data analysis agent with Flights" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-analysis-agent

Ingest Garmin Connect Fitness Data on a Schedule

I want a scheduled Flight that pulls my Garmin Connect training data (activities, plus daily metrics like steps, resting HR, and VO2max) into MotherDuck so I can analyze it in SQL, authenticating headlessly with a cached OAuth token rather than a password. Help me adapt the "Ingest Garmin Connect Fitness Data on a Schedule" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-garmin-connect-ingest

Update a HubSpot List From a MotherDuck Query With a Flight

I want a Flight that runs a MotherDuck SQL query to produce a list of emails and reconciles a HubSpot static contact list to match it (data activation / reverse ETL) — resolving emails to contact IDs, applying the minimal add/remove, with retries and an audit log. Help me adapt the "Update a HubSpot List From a MotherDuck Query With a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-hubspot-list-sync

Query dbt MetricFlow Metrics as a Flight

I want to query metrics from a dbt MetricFlow semantic model on MotherDuck and store scheduled results. Help me adapt the "Query dbt MetricFlow Metrics as a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dbt-metricflow

Ingest Google Analytics 4 into MotherDuck with dlt as a Flight

I want scheduled GA4 reporting data in MotherDuck without hand-writing API calls or INSERTs. Help me adapt the "Ingest Google Analytics 4 into MotherDuck with dlt as a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dlt-ga4-ingest

StatsBomb 360 Football Matches — Flights pipeline + animated Dive

I want a multi-stage Flight pipeline (raw to core to marts, transformed with in-warehouse SQL) paired with a bespoke D3 Dive that renders the data live, all deployed as code on MotherDuck. Help me adapt the "StatsBomb 360 Football Matches — Flights pipeline + animated Dive" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/statsbomb-360-football-matches

Keep DuckLake Reads Fast With Scheduled Maintenance

My DuckLake is accumulating small files, deleted rows, and stale snapshots, and I want scheduled compaction and cleanup tuned to my ingest pattern. Help me adapt the "Keep DuckLake Reads Fast With Scheduled Maintenance" Flight recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-ducklake-maintenance

Sync Google Sheets and MotherDuck With a Flight

I want to sync data both ways between Google Sheets and MotherDuck on a schedule, importing sheets into tables and exporting query results back to sheet tabs as reverse ETL. Help me adapt the "Sync Google Sheets and MotherDuck With a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-google-sheets

Run SQL Transformations in Order

I have a set of CREATE TABLE AS / VIEW / MACRO statements I want to run in dependency order as a DAG inside one Flight, with independent statements running concurrently and automatic retries. Help me adapt the "Run SQL Transformations in Order" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-sql-transformation

NBA Box Scores on MotherDuck Flights and a Dive

I want to pair a scheduled Python Flight ingest with a Dive frontend that reads the data live, all deployed as code on MotherDuck. Help me adapt the "NBA Box Scores on MotherDuck Flights and a Dive" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/nba-box-scores

Incrementally Ingest BigQuery into MotherDuck

I want scheduled, incremental ingestion from BigQuery into MotherDuck using a date-partition watermark with idempotent per-partition DELETE plus INSERT, as part of moving off BigQuery. Help me adapt the "Incrementally Ingest BigQuery into MotherDuck" Flight recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-bigquery-ingest

Map Data Usage and Relationships Across Dives

I want a scheduled, trend-aware map of which data objects my organization's Dives reference and how they connect, mined from the SQL embedded in each Dive. Help me adapt the "Map Data Usage and Relationships Across Dives" Flight recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dive-usage-metrics

Mirror PostgreSQL Tables into MotherDuck With a Flight

I want a config-driven, re-runnable Flight that mirrors selected PostgreSQL tables into MotherDuck with one streaming full-refresh per table, retries, and an audit log. Help me adapt the "Mirror PostgreSQL Tables into MotherDuck With a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-postgres-ingest

Ingest Snowflake Tables into MotherDuck From a Flight

I want a code-driven, re-runnable Flight that ingests Snowflake tables into MotherDuck in two phases (discover an editable inventory, then move the selected tables via Arrow), as part of migrating off Snowflake. Help me adapt the "Ingest Snowflake Tables into MotherDuck From a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-snowflake-ingest

Run a dlt Ingest Pipeline as a Flight

I want Python ingestion that runs on a schedule as a Flight and handles API calls, schema drift, state, and merge behavior with dlt instead of hand-writing every INSERT. Help me adapt the "Run a dlt Ingest Pipeline as a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-dlt-ingest

Alert on Stale Tables From a Flight

I want scheduled freshness monitoring on my MotherDuck tables with dbt-style warn/error age thresholds and a Slack alert when data goes stale. Help me adapt the "Alert on Stale Tables From a Flight" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-freshness-alert

Provision User Databases and Shares

My application gives each user their own isolated MotherDuck database and share, and I want an admin Flight that provisions them from a control table and revokes access when a user goes inactive. Help me adapt the "Provision User Databases and Shares" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-provision-user-databases

Ingest Partitioned S3 Parquet on a Schedule

My data already lands as Hive-partitioned Parquet in S3, and I want a scheduled Flight that incrementally refreshes a MotherDuck table by reading only the partition that changes. Help me adapt the "Ingest Partitioned S3 Parquet on a Schedule" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/flight-scheduled-s3-ingest

Build a MotherDuck Warehouse with dbt and Deploy a Dive

I want to build a MotherDuck warehouse from scratch with dbt-duckdb and then ship a Dive on top of the mart tables. Help me adapt the "Build a MotherDuck Warehouse with dbt and Deploy a Dive" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-duckdb-dwh-starter

Capture Vercel Log Drain Traffic and Classify AI Agents in MotherDuck

I want to capture my Vercel log drain, classify AI bot, agent, and AI-referred human traffic from the user agent and referer, and write it into MotherDuck to query live, with no AWS or S3. Help me adapt the "Capture Vercel Log Drain Traffic and Classify AI Agents in MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/vercel-agent-analytics

Cloudflare Workers Map and Live Vote on MotherDuck

I want to build a full-stack Cloudflare Workers app that reads analytics from a MotherDuck share over the Postgres endpoint and keeps a piece of real-time state (like live votes) at the edge, with a D3 frontend. Help me adapt the "Cloudflare Workers Map and Live Vote on MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/cloudflare-workers-duckoffee

Build Churn Prediction Features with dbt

I want a SQL-first churn feature pipeline on MotherDuck, building feature and label tables with dbt and keeping model training as a separate Python step. Help me adapt the "Build Churn Prediction Features with dbt" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-churn-prediction

Query MotherDuck from Vercel and Next.js

I'm building a Vercel/Next.js backend that reads MotherDuck data through Next.js API routes over the Postgres wire protocol with pooled, parameterized SQL and no DuckDB binary. Help me adapt the "Query MotherDuck from Vercel and Next.js" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/vercel-nextjs

Query MotherDuck from Cloudflare Workers

I want a serverless HTTP API on Cloudflare Workers that queries MotherDuck over the Postgres wire protocol with node-postgres, no DuckDB binary required, and returns JSON. Help me adapt the "Query MotherDuck from Cloudflare Workers" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/cloudflare-workers

Connect to MotherDuck from Node.js with the DuckDB Neo Driver

I want to run DuckDB SQL against MotherDuck from a Node.js service using the native DuckDB Neo driver, including a connection pool for concurrent workloads. Help me adapt the "Connect to MotherDuck from Node.js with the DuckDB Neo Driver" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/nodejs-motherduck

Define and Query Metrics with dbt MetricFlow on MotherDuck

I want to define metrics once with dbt MetricFlow over a fact table and query them identically on a local DuckDB file and on MotherDuck. Help me adapt the "Define and Query Metrics with dbt MetricFlow on MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-metricflow

Visualize MotherDuck Data in Grafana

I want to build Grafana dashboards and time-series panels on top of MotherDuck data, with the DuckDB datasource plugin wired up. Help me adapt the "Visualize MotherDuck Data in Grafana" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/motherduck-grafana

Bridge Local Postgres and MotherDuck with pg_duckdb

I want a hybrid setup where local Postgres and MotherDuck can read each other through pg_duckdb, scanning Postgres from DuckDB and querying MotherDuck from psql. Help me adapt the "Bridge Local Postgres and MotherDuck with pg_duckdb" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/postgres-demo

Ingest API Data into MotherDuck with Python

I need a standalone Python script that pulls JSON from an HTTP API (or an in-memory dataframe) and loads it into a MotherDuck table, with both a pandas path and a typed PyArrow path. Help me adapt the "Ingest API Data into MotherDuck with Python" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/python-ingestion

Clean and Analyze a CSV in the MotherDuck UI

I want a hands-on, query-by-query walkthrough for loading a CSV, profiling it with SUMMARIZE, cleaning messy columns, and answering an analysis question in the MotherDuck web UI. Help me adapt the "Clean and Analyze a CSV in the MotherDuck UI" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/motherduck-ui

Transform Stock Data with SQLMesh on MotherDuck

I want a SQLMesh project on MotherDuck that transforms data through interim, conformed, and mart layers (incremental models, SCD type 2, audits, virtual environments), fed by a dlt ingest. Help me adapt the "Transform Stock Data with SQLMesh on MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/sqlmesh-demo

dbt Dual Execution Across Local DuckDB and MotherDuck

I want to develop dbt models locally against a DuckDB file while still reading from and writing to MotherDuck in the same project, choosing per model whether it lands in the cloud or on disk. Help me adapt the "dbt Dual Execution Across Local DuckDB and MotherDuck" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-dual-execution

Run TPC-DS Models on DuckLake with dbt

I want a dbt project that lands raw tables in DuckLake storage and writes analytics models to native MotherDuck. Help me adapt the "Run TPC-DS Models on DuckLake with dbt" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-ducklake

Run dbt on a Local DuckLake Catalog

I want a lakehouse-style DuckLake catalog (table versioning, snapshots, file compaction) for local dbt development that mirrors a managed DuckLake on MotherDuck. Help me adapt the "Run dbt on a Local DuckLake Catalog" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-local-ducklake

Extract Structured Data From Reviews With dbt And prompt()

I have unstructured text I want to turn into typed columns with an LLM, run entirely as a SQL transformation in dbt with no external API code. Help me adapt the "Extract Structured Data From Reviews With dbt And prompt()" MotherDuck recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-ai-prompt

Build Hacker News Models From S3 With dbt

I want to build dbt models directly on Parquet/CSV in S3 without copying the data first, running locally against DuckDB or in the cloud against MotherDuck. Help me adapt the "Build Hacker News Models From S3 With dbt" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dbt-ingestion-s3

Replicate PostgreSQL Tables to MotherDuck with dlt

I need to copy and refresh tables from a PostgreSQL database into MotherDuck with a dlt pipeline, with tunable extract, normalize, and load parallelism. Help me adapt the "Replicate PostgreSQL Tables to MotherDuck with dlt" recipe to my own data and use case, using it as a guide: https://motherduck.com/docs/cookbook/dlt-db-replication