DuckDB is one of the simplest, fastest databases you can use - and it's completely free! The beauty of DuckDB lies in its simplicity of setup and use. Here's a quick tutorial to help you get your hands dirty with DuckDB in 5 minutes or less
Step #1: Install DuckDB
Installing DuckDB is a breeze. Open Terminal on your Mac and type this:
brew install duckdb
Step #2: Verify if the installation has been completed
All you do is type this command:
duckdb --version
The output should look something like this:
Step #3 - We're ready to go. Fire it up!
At this point, DuckDB is already installed in your machine. To begin with I would recommend that you navigate to a folder (using terminal) which contains CSV / Parquet files that you would like to analyze. Then, simply type this command in your terminal to get started:
duckdb
At this point, duckdb is already setup and working. No more installations, no more dependencies. Easy right? Now let’s get into some analysis.
Step #4 - My first SQL queries, directly on CSV files
Run your first query on the CSV file, without any pre-processing. Assume your file is called 'input.csv'
SELECT * from input.csv limit 10;
That's it - you're already up and running with DuckDB. Here are some more commands for you to work with
1. Get a list of all commands you can work with
.help
2. Set the working directory (for example where your files maybe present) - replace WORKING_DIRECTORY with your working directory
.cd WORKING_DIRECTORY
3. Persist your database to a file, or open an older database you've already worked with (by default DuckDB loads everything in-memory) - replace FILENAME with the file name where you would like to persist your db
.open FILENAME
4. Show the list of tables in your current database
SHOW TABLES
Conclusion
Hope you enjoyed this article. This is a series of 5-minute articles for anyone looking to quickly get set up on the tools of the modern data stack.
Comments