---
title: "Simple way to convert CSV and Parquet files | MotherDuck"
description: "Want convert CSV to Parquet or vice versa? In this YouTube short, Mehdi shows you how to convert using DuckDB as a Swiss Army Knife to convert data formats."
canonical: "https://motherduck.com/videos/simple-way-to-convert-csv-and-parquet-files/"
---

[BACK TO VIDEOS](/videos/)

[YouTube](/videos/?category=YouTube#videos-and-webinars-library)[Short](/videos/?category=Short#videos-and-webinars-library)[Tutorial](/videos/?category=Tutorial#videos-and-webinars-library)

# Simple way to convert CSV and Parquet files

2024/01/17Featuring: [Mehdi Ouazza](/authors/mehdi-ouazza/)

As developers, we live in the terminal. It’s our command center for everything from Git commits to running applications. But we all have those small, annoying tasks that break our flow—the little papercuts of the development cycle. One of the most common? File format conversion.

You have a [Parquet](/learn-more/why-choose-parquet-table-file-format/) file, but a legacy tool or a colleague needs it in [CSV](/blog/taming-wild-csvs-with-duckdb-data-engineering/) format. Or maybe you have a massive CSV that you want to compress into the more efficient Parquet format. What's your go-to move? Do you spin up a Jupyter notebook and `import pandas`? Do you write a quick, one-off Python script? Or do you resort to a sketchy online file converter?

These interruptions, while small, add up. But what if the perfect tool for the job was already on your machine, ready to go?

Enter DuckDB. While you might know it as a powerful embedded analytical database, it's also a versatile Swiss army knife for your data. Because it's a lightweight, serverless tool that speaks fluent SQL and natively understands formats like Parquet, CSV, and [JSON](/blog/analyze-json-data-using-sql/), it's the perfect utility for lightning-fast file conversions directly from your command line.

Let's build a powerful, reusable conversion utility in just a few minutes.

### Instant File Conversion with a DuckDB One-Liner

First things first, you need the `duckdb` CLI. If you're on macOS, installation is a single command with Homebrew.

```
Copy codebrew install duckdb
```

For other operating systems, check out the [official installation documentation](https://duckdb.org/docs/installation/index).

Once installed, you have everything you need. Let's say you have a file named `data.parquet` and you want to convert it to `data.csv`. The magic is a single command that leverages DuckDB's powerful `COPY` statement.

```
Copy codeduckdb -c "COPY (SELECT * FROM 'data.parquet') TO 'data.csv' (HEADER, DELIMITER ',');"
```

Let's break down this command to see what's happening:

- `duckdb -c "..."`: This is the key to using DuckDB as a scripting tool. The `-c` flag tells DuckDB to execute the SQL command that follows and then immediately exit. No interactive shell, no fuss—just pure, scriptable execution.

- `COPY (...) TO 'data.csv'`: This is the workhorse. The `COPY` command is incredibly efficient at moving data into and out of DuckDB.

- `(SELECT * FROM 'data.parquet')`: Instead of copying from a table, we're telling DuckDB to copy the result of a query. The magic here is that DuckDB can query files like Parquet or CSV directly, _as if they were database tables_. It automatically infers the file type and schema from the file extension.

- `(HEADER, DELIMITER ',')`: These are options specific to the output format. Here, we're telling DuckDB to include a header row in our final CSV file.

And that's it. In the time it would have taken you to open a new editor tab, you've converted your file.

### Building a Reusable Conversion Script

That one-liner is great, but we can make it even better. The real power of the command line comes from creating reusable, generic tools.

Let's wrap this logic into a simple Bash script. Create a file named `file-converter.sh` somewhere convenient, like `~/scripts/`.

```
Copy code#!/bin/bash
# file-converter.sh

# Check if two arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0  "
exit 1
fi

INPUT_FILE=$1
OUTPUT_FILE=$2

duckdb -c "COPY (SELECT * FROM '${INPUT_FILE}') TO '${OUTPUT_FILE}';"

echo "Successfully converted ${INPUT_FILE} to ${OUTPUT_FILE}"
```

Make the script executable:

```
Copy codechmod +x ~/scripts/file-converter.sh
```

Now, you have a generic script that takes an input file and an output file as arguments. The final step is to create a shell alias for ultimate convenience. Open your `.zshrc`, `.bashrc`, or equivalent shell configuration file and add this line:

```
Copy code# Add to your .zshrc or .bashrc
alias dconvert='~/scripts/file-converter.sh'
```

Restart your terminal or run `source ~/.zshrc` to apply the changes. Now, witness your new superpower. You can convert files back and forth with a simple, memorable command.

**Convert Parquet to CSV:**

```
Copy codedconvert data.parquet data.csv
# Successfully converted data.parquet to data.csv
```

**Convert CSV to Parquet:**

```
Copy codedconvert data.csv data.parquet
# Successfully converted data.csv to data.parquet
```

It doesn't get simpler than that. You've just built a universal file conversion utility that is faster and more reliable than a custom script and safer than any online tool.

### Conclusion: More Than Just Conversion

We started with a simple problem and ended with an elegant, reusable solution. With one small script, you've added a powerful tool to your developer toolkit, powered by DuckDB.

But don't forget what's happening inside that command. You aren't just copying bytes; you're running a full-fledged SQL query. This opens up a world of possibilities that go far beyond the simple 1-to-1 conversion our `dconvert` alias handles.

What if you only wanted a subset of the data? For more complex tasks, you can bypass the alias and use the `duckdb -c` command directly to run a more powerful query.

```
Copy code# Filter for specific rows before converting
duckdb -c "COPY (SELECT * FROM 'data.parquet' WHERE category = 'A') TO 'filtered_data.csv' (HEADER, DELIMITER ',');"
```

What if you only needed a few columns?

```
Copy code# Select specific columns
duckdb -c "COPY (SELECT user_id, event_timestamp FROM 'logs.parquet') TO 'events.csv' (HEADER, DELIMITER ',');"
```

The `SELECT` statement is your playground. You can perform filtering, transformations, and even simple aggregations as part of your conversion pipeline, all within that single command.

---

### Get Started Today

- Try this out and share your favorite DuckDB one-liners with us on [Twitter](https://twitter.com/motherduckcorp)!

- For more details on the options available, check out the official DuckDB documentation for the [`COPY` command](https://duckdb.org/docs/stable/sql/statements/copy).

- When your challenges go beyond local files, see how [MotherDuck](https://motherduck.com/) brings the power of DuckDB to the cloud for serverless, collaborative analytics.

## Transcript

Copy

0:00when working with Loca file it's pretty common to have them to convert it to another format CSV to park or park to CSV ddb is an embed lightwe analytical database and therefore versatile like a swis army knife so perfect for search File conversion operations on Mac OS you can install Doug DB with Homebrew check the link in the description if you are

0:21on another home operating system then with one line of code you can easily do a conversion the dub we see plag just mean that we are going to launch ddb and then it after the process we read our search file which is here an example.

0:34parket and then use copy to convert the results of this query to another file format here example. CSV but it cannot be simpler than that well actually it can so let's package this in the back scripts to make even more generate now I can call my script with this alas specify path of my file and convert it

0:55and boom now I can convert back and forth it cannot get simpler than that I think

## Related Videos

[1:02:00](/videos/ai-for-sales-marketing-teams/)[2026-05-07](/videos/ai-for-sales-marketing-teams/)

### [AI Data Analysis for Sales & Marketing Teams: Real Demos, No SQL Required](/videos/ai-for-sales-marketing-teams/)

Watch how an AE and a marketer use AI to analyze their own business data without writing SQL or waiting on a data team.

Webinar

AI, ML and LLMs

MotherDuck Features

Tutorial

[1:00:14](/videos/building-ai-chatbot-saas-mcp/)[2026-03-11](/videos/building-ai-chatbot-saas-mcp/)

### [Building an Analytics Chatbot for your SaaS app in 1 day](/videos/building-ai-chatbot-saas-mcp/)

Learn how to build a conversational AI chatbot for your SaaS product using the MotherDuck MCP server, with scoped data access and streaming responses.

Webinar

AI, ML and LLMs

Tutorial

MotherDuck Features

[2026-01-27](/videos/preparing-data-warehouse-for-ai/)

### [Preparing Your Data Warehouse for AI: Let Your Agents Cook](/videos/preparing-data-warehouse-for-ai/)

Jacob and Jerel from MotherDuck showcase practical ways to optimize your data warehouse for AI-powered SQL generation. Through rigorous testing with the Bird benchmark, they demonstrate that text-to-SQL accuracy can jump from 30% to 74% by enriching your database with the right metadata.

AI, ML and LLMs

SQL

MotherDuck Features

Stream

Tutorial

[View all](/videos/)