How to Open & Query a DuckDB Database: Step-by-Step Tutorial
🦆 Open the DuckDB Viewer and follow along with this tutorial.
Open Tool →Steps
This tutorial walks you through opening, querying, and exporting a DuckDB database using the free FinancialDataTools.com DuckDB Viewer. The tool uses DuckDB-Wasm — the official WebAssembly build of the DuckDB analytical engine — to run entirely inside your browser. Nothing is sent to any server.
Try the DuckDB Viewer — runs entirely in your browser and never uploads your files.
Open the DuckDB Viewer →Step 1: Locate Your DuckDB File
Find the .duckdb or .db file you want to inspect. DuckDB databases are created by the DuckDB engine and appear in a variety of data engineering and analytics contexts:
- DuckDB databases created in Python with
import duckdb; con = duckdb.connect('mydb.duckdb') - DuckDB databases created in R with the
duckdbpackage - Output files from data pipelines that use DuckDB as a local data warehouse
- Backtest result databases from algorithmic trading frameworks
- Financial analytics databases built with DuckDB for local OLAP queries
The viewer works with DuckDB-native database files. SQLite databases should be opened in the SQLite Viewer; Parquet files should be opened in the Parquet Viewer.
Step 2: Open the DuckDB Viewer
Navigate to financialdatatools.com/viewers/duckdb-viewer/ in any modern desktop browser (Chrome, Firefox, Edge, or Safari). No login, account, or installation is required. The viewer works best on desktop.
Step 3: Load Your Database
There are two ways to open your database:
- Click the green "Open File" button in the toolbar and select your
.duckdbor.dbfile. - Drag and drop your file anywhere onto the viewer window.
Loading happens in three stages, each shown with a status message:
- Initialising DuckDB-Wasm — the DuckDB engine loads into the browser (first load only; cached for subsequent files)
- Reading Parquet metadata — the database schema is read without loading row data
- Loading rows — the first page of rows is fetched
Once loaded, the tab bar shows a tab for each table in your database, and the stats bar shows the total row count, visible rows, column count, and the current table name.
Step 4: Browse Tables
Click any tab to switch between tables. The data grid shows your rows in a spreadsheet-style layout. Each column header displays:
- The column name — click to sort ascending or descending
- A type badge showing the DuckDB type (INT, FLOAT, TEXT, BOOL, DATE, BLOB)
- A tooltip with the full type string (e.g.,
DECIMAL(18,6)) on hover - A filter button for column-level filtering
Click any cell to open the Cell Detail Panel on the right, which shows the full untruncated value. Nested types (LIST, STRUCT, MAP) are displayed as formatted JSON in the detail panel.
Step 5: Sort and Filter Rows
Sorting: Click any column header to sort. First click: ascending. Second: descending. Third: original order.
Global search: Type in the search box in the toolbar to search across all visible columns. Results update in real time.
Column filters: Click the filter icon in any column header. Two modes:
- Values mode: A checklist of distinct values in that column. Uncheck values to hide matching rows.
- Conditions mode: Apply conditions like "contains", "equals", "greater than", or "is empty". Combine two conditions with AND or OR.
Column filters operate on the currently loaded page. For filtering across millions of rows in a large database, use the SQL panel in Step 6 with a WHERE clause instead.
Step 6: Run a SQL Query
The SQL panel is the most powerful feature of the DuckDB Viewer. Click the amber SQL button in the toolbar to open it. The panel contains a resizable multi-line text editor.
Type any DuckDB SELECT statement and press Ctrl+Enter (or Cmd+Enter on Mac), or click the ▶ Run button. The results replace the current table view in the grid.
A few example queries to get you started:
Preview the first 100 rows of a table:
SELECT * FROM my_table LIMIT 100;
Filter rows and select specific columns:
SELECT trade_date, symbol, quantity, price
FROM trades
WHERE trade_date >= '2025-01-01'
AND symbol = 'AAPL'
ORDER BY trade_date DESC;
Aggregate data:
SELECT
symbol,
COUNT(*) AS num_trades,
SUM(quantity * price) AS total_notional,
AVG(price) AS avg_price
FROM trades
GROUP BY symbol
ORDER BY total_notional DESC;
Window function — rolling average:
SELECT
trade_date,
close_price,
AVG(close_price) OVER (
ORDER BY trade_date
ROWS BETWEEN 19 PRECEDING AND CURRENT ROW
) AS ma_20d
FROM prices
WHERE symbol = 'SPY'
ORDER BY trade_date;
After running a query, the results appear in the grid with the same sorting, filtering, column detail, and export capabilities as the regular table view. The status line below the editor shows the number of rows returned.
Any SQL syntax errors or runtime errors are displayed in red below the Run button.
Step 7: Inspect the Schema
Click the Schema button in the toolbar to open the column schema modal for the active table (not available in SQL query mode). It shows each column's name and full DuckDB type string, derived from a DESCRIBE query. Use Copy Schema to copy the column list as plain text.
Step 8: Export Your Data
Click the Export button in the toolbar to open the export dialog. Four formats are available:
- CSV — comma-separated; NULL as empty string; ready for pandas, Excel, or re-import
- JSON — array of objects with column names as keys
- Excel (.xlsx) — workbook with frozen header row, auto-sized columns, and attribution sheet
- TSV — tab-separated; useful when values may contain commas
Three export scopes let you control the data exported:
- Filtered view — exports only the rows visible after applying search and column filters
- Full table — queries DuckDB for all rows in the active table and exports them
- All tables (Excel only) — exports every table to a single Excel workbook with one worksheet per table
Tip: Use the All tables Excel export to convert an entire DuckDB database into a multi-sheet workbook that you can share with stakeholders who don't have DuckDB installed.
