home / skills / windmill-labs / windmill / write-script-duckdb
This skill helps you write DuckDB queries with parameter binding, external connections, and ducklake integration for streamlined data access.
npx playbooks add skill windmill-labs/windmill --skill write-script-duckdbReview the files below or copy the command above to add this skill to your agents.
---
name: write-script-duckdb
description: MUST use when writing DuckDB queries.
---
## CLI Commands
Place scripts in a folder. After writing, run:
- `wmill script generate-metadata` - Generate .script.yaml and .lock files
- `wmill sync push` - Deploy to Windmill
Use `wmill resource-type list --schema` to discover available resource types.
# DuckDB
Arguments are defined with comments and used with `$name` syntax:
```sql
-- $name (text) = default
-- $age (integer)
SELECT * FROM users WHERE name = $name AND age > $age;
```
## Ducklake Integration
Attach Ducklake for data lake operations:
```sql
-- Main ducklake
ATTACH 'ducklake' AS dl;
-- Named ducklake
ATTACH 'ducklake://my_lake' AS dl;
-- Then query
SELECT * FROM dl.schema.table;
```
## External Database Connections
Connect to external databases using resources:
```sql
ATTACH '$res:path/to/resource' AS db (TYPE postgres);
SELECT * FROM db.schema.table;
```
## S3 File Operations
Read files from S3 storage:
```sql
-- Default storage
SELECT * FROM read_csv('s3:///path/to/file.csv');
-- Named storage
SELECT * FROM read_csv('s3://storage_name/path/to/file.csv');
-- Parquet files
SELECT * FROM read_parquet('s3:///path/to/file.parquet');
-- JSON files
SELECT * FROM read_json('s3:///path/to/file.json');
```
This skill provides concise guidance for writing DuckDB queries inside scripts used by the platform. It explains how to declare parameters, attach Ducklake and external databases, read S3 files, and deploy scripts with the CLI. Use it to author safe, parameterized queries that integrate with external resources and data lakes.
Arguments are declared in SQL comments and referenced with the $name syntax, letting the runtime substitute values safely. You attach Ducklake instances or external database resources using ATTACH statements, then run SELECT or read_* functions (read_csv, read_parquet, read_json) to query local files or S3. After writing scripts, generate metadata and push deployments using the CLI so scripts become callable webhooks or workflows.
How do I declare and use a query parameter?
Add a comment like -- $name (text) = default above the query and reference it as $name in SQL; the runtime will substitute the provided value.
How do I connect to my data lake or an external DB?
Use ATTACH 'ducklake' AS dl or ATTACH 'ducklake://my_lake' AS dl for Ducklake. For external DBs, ATTACH '$res:path/to/resource' AS db (TYPE postgres) and query db.schema.table.