DuckDB Cheat Codes
DuckDB Cheat Codes for in-process analytical SQL, direct Parquet reading, Pandas zero-copy, and SUMMARIZE. 20 essential cheat codes ready to copy and execute.
Query local in-memory or file datasets.
SELECT col1, col2 FROM tbl; SELECT country, amount FROM sales; Filter output rows.
SELECT * FROM tbl WHERE col = val; SELECT * FROM orders WHERE status = 'shipped'; Join datasets in vectorized execution engine.
SELECT * FROM t1 JOIN t2 ON t1.id = t2.fk; SELECT u.name, s.amount FROM users u JOIN sales s ON u.id = s.user_id; Vectorized aggregation grouping.
SELECT col, AVG(x) FROM tbl GROUP BY col; SELECT category, AVG(price) FROM products GROUP BY category; Query Parquet files directly using SQL without import.
SELECT * FROM read_parquet('file.parquet'); SELECT country, COUNT(*) FROM read_parquet('data/sales_2026.parquet') GROUP BY country; Export query results directly into compressed Parquet file.
COPY (SELECT ...) TO 'output.parquet' (FORMAT PARQUET); COPY (SELECT * FROM orders WHERE year = 2026) TO 'orders_2026.parquet' (FORMAT PARQUET, COMPRESSION SNAPPY); Auto-detect CSV schema and query file directly.
SELECT * FROM read_csv_auto('file.csv'); SELECT * FROM read_csv_auto('logs/*.csv') WHERE status = 500; Generate statistical summary (nulls, min, max, avg) for all columns.
SUMMARIZE SELECT * FROM tbl; SUMMARIZE SELECT * FROM read_parquet('dataset.parquet'); Filter window function output directly without subquery wrappers.
SELECT col, ROW_NUMBER() OVER(PARTITION BY grp ORDER BY val DESC) as rn FROM tbl QUALIFY rn = 1; SELECT customer_id, order_date, amount, ROW_NUMBER() OVER(PARTITION BY customer_id ORDER BY amount DESC) as rn FROM orders QUALIFY rn = 1; Rotate quarterly row values into reporting columns.
PIVOT (SELECT year, quarter, sales FROM tbl) ON quarter IN ('Q1', 'Q2') USING SUM(sales); PIVOT (SELECT year, quarter, sales FROM quarterly_sales) ON quarter IN ('Q1', 'Q2', 'Q3', 'Q4') USING SUM(sales); Query Python Pandas DataFrame directly in DuckDB.
import duckdb; duckdb.query('SELECT * FROM df'); import duckdb, pandas as pd; df = pd.DataFrame({'a': [1,2]}); duckdb.query('SELECT AVG(a) FROM df').df(); Enable HTTP and S3 remote file querying.
INSTALL httpfs; LOAD httpfs; INSTALL httpfs; LOAD httpfs; SELECT * FROM 's3://my-bucket/data.parquet' LIMIT 10; Store S3 access key and secret token.
CREATE SECRET s3_dev (TYPE S3, KEY_ID '...', SECRET '...'); CREATE SECRET s3_dev (TYPE S3, KEY_ID 'AKIA...', SECRET 'wJal...', REGION 'us-east-1'); Display vectorized query execution plan and timing metrics.
EXPLAIN ANALYZE SELECT ...; EXPLAIN ANALYZE SELECT COUNT(*) FROM read_parquet('large_file.parquet'); Output JSON query profiling timings to file.
PRAGMA enable_profiling = 'json'; PRAGMA profiling_output = 'prof.json'; PRAGMA enable_profiling = 'json'; PRAGMA profiling_output = 'prof.json'; Create table from Parquet or CSV query result.
CREATE TABLE tbl AS SELECT * FROM read_parquet('file.parquet'); CREATE TABLE orders_cache AS SELECT * FROM read_parquet('s3://bucket/orders.parquet'); Query JSON or NDJSON files directly.
SELECT * FROM read_json_auto('file.json'); SELECT * FROM read_json_auto('events/*.json') WHERE type = 'signup'; Rank rows without rank gaps.
SELECT col, DENSE_RANK() OVER(ORDER BY val DESC) FROM tbl; SELECT player, score, DENSE_RANK() OVER(ORDER BY score DESC) FROM leaderboard; Combine result rows from multiple queries preserving duplicates.
SELECT col FROM t1 UNION ALL SELECT col FROM t2; SELECT email FROM leads UNION ALL SELECT email FROM customers; Rename column inside table schema.
ALTER TABLE tbl RENAME COLUMN old_name TO new_name; ALTER TABLE users RENAME COLUMN fname TO first_name; No cheat codes found matching your search term.