---
title: "DuckDB Tricks – Part 1"
description: "Five DuckDB SQL tricks for interactive use, built around a small example CSV and DuckDB's friendly SQL shorthands such as FROM-first syntax."
url: "https://swe.quest/articles/duckdb-tricks-part-1-99ece69aab247417"
canonical: "https://duckdb.org/2024/08/19/duckdb-tricks-part-1.html"
source: "DuckDB"
published: "2024-08-19"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["sql","databases","analytics"]
---

# DuckDB Tricks – Part 1

A post on [DuckDB](https://swe.quest/sources/duckdb.md), published 2024-08-19, 5 min read, How-to. Original: [https://duckdb.org/2024/08/19/duckdb-tricks-part-1.html](https://duckdb.org/2024/08/19/duckdb-tricks-part-1.html)

## Summary

Five DuckDB SQL tricks for interactive use, built around a small example CSV and DuckDB's friendly SQL shorthands such as FROM-first syntax. Casting to DECIMAL(15, 3) pretty-prints floats while keeping them numeric, unlike printf. CREATE TABLE ... AS FROM ... LIMIT 0 copies a schema without data, and ORDER BY hash(rowid + 42) gives a deterministic shuffle (the offset matters because hash(0) is 0). The read\_csv types argument overrides auto-detected column types, and COPY can rewrite a CSV in place, which a naive Unix shell redirect cannot do.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- basic SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

DuckDB, CSV, read\_csv

## Related posts

- [Ducks in a Column](https://swe.quest/articles/ducks-in-a-column-ce42623eb848a791.md): DuckDB · 2026-11-10 · Medium · 12 min read · SQL, Analytics & OLAP, Query engines
  DuckDB stores data by column and processes it in vectors of 2,048 values, which drives its compression, projection pushdown and aggregation speed.
- [Even Friendlier SQL with DuckDB](https://swe.quest/articles/even-friendlier-sql-with-duckdb-26e7b4e6715ab305.md): DuckDB · 2023-08-23 · Medium · 16 min read · SQL, Analytics & OLAP, Databases
  DuckDB extends SQL syntax with features that simplify everyday queries and enable dynamic analysis.
- [Gems of DuckDB 2.0.0](https://swe.quest/articles/gems-of-duckdb-2-0-0-0cf205137ec12582.md): DuckDB · 2026-10-26 · Medium · 8 min read · Databases, SQL, Analytics & OLAP, Python
  DuckDB 2.0.0 LTS includes a set of smaller features beyond its headline items.
- [The Journey to Zero-Copy: How chDB Became the Fastest SQL Engine on Pandas DataFrame](https://swe.quest/articles/the-journey-to-zero-copy-how-chdb-became-the-fastest-sql-engine-on-pandas-b4ab858523515f13.md): ClickHouse · 2026-01-09 · Medium · 8 min read · Python, Performance engineering, Analytics & OLAP, Query engines
  chDB, ClickHouse embedded as a Python library, removed the four serialization steps that made every v1 query take over 100ms by reading Pandas DataFrames in place.
- [Text2SQL using Hugging Face Dataset Viewer API and Motherduck DuckDB-NSQL-7B](https://swe.quest/articles/text2sql-using-hugging-face-dataset-viewer-api-and-motherduck-duckdb-nsql-7b-7024872a0cc79ab7.md): Hugging Face · 2024-04-04 · Medium · 7 min read · LLMs, SQL, Analytics & OLAP, Python
  DuckDB-NSQL-7B, a Llama-2-7B model fine-tuned on general SQL and then DuckDB text-to-SQL pairs, can turn plain-language questions into DuckDB SQL that runs directly against Hugging Face datasets.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
