Practical Postgres 🐘 CDC with StreamkapLivestream July 15

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

34 of 34 results

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

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

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