opyeb QueryDeck

Turn a CSV into a SQLite table inside your browser

2026-11-28 · 2 min read

A CSV looks universal — rows and commas — yet every question about it means rebuilding filters and sorts. Converting it to a table inside the browser turns that repetition into one line of SQL, and the file never leaves the machine.

Why query instead of scrolling

A spreadsheet is good for looking. It is poor at remembering. Next month the same question needs the same filter chain rebuilt by hand, while a SQL statement keeps the question itself as text: "top five regions by revenue" runs unchanged when the data is replaced.

The second difference is reproducibility. A stray sort in a spreadsheet silently changes the answer, whereas SQL without ORDER BY makes unordered output obvious. A single query also explains a result to a colleague better than a screenshot of ten filter settings.

Four steps from file to table

First the file is read. The browser File API brings it into memory; no server is involved. Second, the delimiter is detected by counting commas, tabs or semicolons outside quotes on the first line.

Third, the first row becomes the header and each column is scanned to choose a type: all integers means INTEGER, all numbers means REAL, anything else TEXT. Fourth, empty fields become NULL and the table is created. Understanding these four steps tells you where to look when a result seems wrong.

Three first queries

Once the table exists, these three statements describe its shape: a preview, a row count, and a filtered row count.

SELECT * FROM orders LIMIT 20;
SELECT COUNT(*) FROM orders;
SELECT COUNT(*) FROM orders WHERE status = 'refunded';

Where it usually goes wrong

The commonest problem is a number that arrives as text. A thousands separator inside the value ("1,200") or a currency symbol stops numeric inference; strip it with REPLACE and CAST. Dates behave the same way: ISO dates such as 2026-09-01 sort correctly as text, but 09/01/2026 does not and needs strftime.

Finally, duplicate header names overwrite each other, so the second column silently disappears. Check the header row before loading, and prefer short, lowercase names without spaces.

Value in the fileInferred typeWhat to check
42, 7, 19INTEGERnegatives and zero
1,200 / $3,500TEXTstrip separators, then CAST
2026-09-01TEXTISO dates sort as text
empty cellNULLCOUNT(*) versus COUNT(col)
Y / N, trueTEXTdecide whether to map to 0/1

Questions

Must the CSV be UTF-8?

Browsers read UTF-8 by default. A file exported from Excel in a legacy codepage can show broken characters, so choose "CSV UTF-8" when saving.

What if the file has no header row?

The first data row becomes the header, so column names turn into values. Add a header line in a text editor and load it again.

Sources

Every query in this guide runs against the built-in sample data.

Open the lab