DuckDB Example

code
duckdb
Published

February 17, 2024

Test DuckDB features based on quarto.

All the code below can be copied and executed in a jupyter notebook.

Install dependencies

!pip install duckdb jupysql --quiet

Basic configuration

import duckdb

conn = duckdb.connect()

jupysql configuration

%load_ext sql

%config SqlMagic.autopandas = True
%config SqlMagic.feedback = 0
%config SqlMagic.displaycon = True
%config SqlMagic.displaylimit = 10

%sql conn --alias duckdb-native

Demo data

Refer to Jupyter Notebooks

%%sql --save short_trips --no-execute
SELECT *
FROM 'https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2021-01.parquet'
WHERE trip_distance < 6.3
Skipping execution...
%sqlplot histogram --table short_trips --column trip_distance --bins 10 --with short_trips