Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with DuckDB

You're reading from   Getting Started with DuckDB A practical guide for accelerating your data science, data analytics, and data engineering workflows

Arrow left icon
Product type Paperback
Published in Jun 2024
Publisher Packt
ISBN-13 9781803241005
Length 382 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Ned Letcher Ned Letcher
Author Profile Icon Ned Letcher
Ned Letcher
Simon Aubury Simon Aubury
Author Profile Icon Simon Aubury
Simon Aubury
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Chapter 1: An Introduction to DuckDB FREE CHAPTER 2. Chapter 2: Loading Data into DuckDB 3. Chapter 3: Data Manipulation with DuckDB 4. Chapter 4: DuckDB Operations and Performance 5. Chapter 5: DuckDB Extensions 6. Chapter 6: Semi-Structured Data Manipulation 7. Chapter 7: Setting up the DuckDB Python Client 8. Chapter 8: Exploring DuckDB’s Python API 9. Chapter 9: Exploring DuckDB’s R API 10. Chapter 10: Using DuckDB Effectively 11. Chapter 11: Hands-On Exploratory Data Analysis with DuckDB 12. Chapter 12: DuckDB – The Wider Pond 13. Index 14. Other Books You May Enjoy

Exporting data

So far, we have been importing data from a variety of data sources into DuckDB. We also often need to export data from DuckDB into a file, perhaps to transfer to another database system or to share our data with others. Let’s discuss how we can achieve that in the following sections.

Exporting a table into a CSV file

We can use the COPY ... TO command to export data from DuckDB to an external CSV, JSON, or Parquet file. This command can be called either with a table name or a query and will export the corresponding data to disk in the desired file format. Let’s try this out by creating a subset of our bike-share dataset and exporting it as a CSV file.

We’ll first create a table called bike_readings_april containing bike rides that occurred in April:

CREATE OR REPLACE TABLE bike_readings_april AS
SELECT *
FROM bikes
WHERE RUNDATE BETWEEN '2017-04-01' AND '2017-04-30';

With the bike_readings_april table created, let...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime