PARAS MADAN
All writing

Latest in AI

How to Use the Redshift DuckDB Extension Without Pulling the Whole Table

Install the matching DuckDB extension, authenticate with IAM, and check which parts of a warehouse-to-local query run where.

The Redshift DuckDB extension, released December 1, lets a local DuckDB session run Redshift SQL and receive the result as a DuckDB table. For an analyst comparing a small local CSV against warehouse data, the useful pattern is to do the heavy aggregation in Redshift and bring back the narrow result.

This isn't the same as Athena's DuckDB engine preview. Athena runs a managed workgroup's queries on a DuckDB-based engine. With the Redshift extension, your client is DuckDB but the SQL you send to the warehouse still uses Redshift semantics.

Install the extension in the runtime that runs the query

Start by running SELECT version(); inside your notebook or CLI. AWS documents a binary built for DuckDB 2.0.1, not every version of DuckDB. Check the version from the process that actually runs your job. Your terminal can have a compatible DuckDB CLI while your notebook imports a different Python package.

The documented setup commands are:

INSTALL redshift FROM aws.amazon.com;
LOAD redshift FROM aws.amazon.com;

Install makes the binary available to the runtime. Load enables it in that session. Check the client and platform before changing your AWS roles if the error occurs at either of these steps.

Check the identity before joining data

The AWS setup guide covers provisioned clusters and Serverless workgroups. It documents IAM authentication through the default credential chain, a named profile or a DuckDB secret, with an included ODBC driver. In a staging workgroup, attach using the documented settings for your target and start with SELECT * FROM redshift_query('rs', 'SELECT current_user');, where rs is your attach alias.

Compare that result with the expected warehouse identity, then run a small read from a table you already have permission to access. A successful attach does not mean Redshift has granted use of every schema. If that small read fails, check the database grants in AWS's authentication guide instead of switching to a broader role.

Decide which work belongs on which side

Imagine a CSV with 200 campaign IDs and a large events table with daily records. Have Redshift return one row per campaign and day for the week you need, with just the ID and counts. Join that result with the CSV in DuckDB. Sending a remote SELECT * and relying on a local filter can move far more data than you need. Write the warehouse filter and aggregation into the SQL you pass to redshift_query so its location is explicit.

Check row counts and join key types on both sides. A CSV that reads IDs as numbers might drop leading zeros, and duplicate IDs in the CSV can inflate totals after the join. Compare grouped totals with a known warehouse query before letting an AI analysis tool run the workflow repeatedly.

The extension is available under Apache 2.0, but that doesn't make your warehouse queries or data transfers free. Track Redshift execution and the number of rows returned separately from local join time, and choose this path when a compressed result really is enough.

I'm Paras Madan. I help teams make data workflows and AI product demos prove the expensive parts before they add more automation.

Book a 30-minute call