A CSV cleaning checklist: eight checks before you load
Half of the odd behaviour in SQL comes from the file, not the query. Five minutes of checking before loading saves an hour of debugging.
1. Encoding
Broken characters usually mean the file is not UTF-8. Browsers read UTF-8 by default, so pick "CSV UTF-8" when exporting from a spreadsheet. For an existing file, re-save it from a text editor with the right encoding.
2. Delimiter and 3. Quotes
A value containing the delimiter must be quoted, or it silently creates an extra column. A quote inside a quoted value is escaped by doubling it ("").
Some locales use a semicolon as delimiter and a comma as decimal mark. Check the first line, and decide whether a comma inside a number is a thousands separator or a decimal point.
| Symptom | Cause | Fix |
|---|---|---|
| one extra column | comma inside a value | wrap the value in quotes |
| row breaks early | line break inside a value | wrap the value in quotes |
| everything in one column | wrong delimiter | check tab or semicolon |
| broken characters | legacy encoding | re-save as UTF-8 |
| numbers stored as text | separators or currency symbols | REPLACE then CAST |
4. Headers and 5. Types
A duplicate header name overwrites the earlier column, and names differing only by case or spaces cause confusion. Keep headers short, unique and preferably lowercase with underscores.
One text value in a numeric column makes the whole column TEXT, so SUM returns zero and sorting becomes alphabetical. Find the mixed values before that happens.
SELECT typeof(revenue) AS t, COUNT(*) FROM orders GROUP BY t;
6. Dates, 7. Units, 8. Duplicates
ISO dates (2026-09-01) are safest. 09/01/2026 could be either day or month. Mixed currencies make a total meaningless, so split the column or state the conversion rate.
Finally check duplicates. A column that should be unique, such as an order id, inflates joins and totals when repeated. COUNT(*) against COUNT(DISTINCT id) exposes it immediately.
SELECT COUNT(*) AS rows, COUNT(DISTINCT order_id) AS uniq
FROM orders;
Check again after cleaning
After editing a file, run the checks once more: did the row count change, are the columns the same, are numeric columns still numeric? A broken quote merges or splits rows and changes the count without any error.
Keep the original. If only the cleaned copy survives, there is no way to see what changed. In QueryDeck it is safer to leave the file untouched and clean the column inside the query with REPLACE and CAST.
Questions
My exported CSV keeps breaking Korean text.
Choose "CSV UTF-8 (comma delimited)" when saving. A plain CSV is written in a system codepage that may not survive.
How do I spot a line break inside a value?
Search the file for a quoted value spanning lines. A correct parser joins those lines into a single row.
Sources
Every query in this guide runs against the built-in sample data.
Open the lab