The conversion took ten seconds and reported no error, yet the spreadsheet is wrong. One row has nine columns where the header has seven. A column that should be mostly empty is full of the word NULL. The footer line from the terminal is nowhere in the file. It looks like the converter mangled your data.
Usually it did not. The SQL to CSV Formatter on Ovatly follows a small set of predictable rules when it reads a printed table, and each of these symptoms maps to one of them. This guide goes through the five usual causes: lost headers, NULL values, quoted fields, pipe characters and trimmed padding, plus the summary line that disappears on purpose.
Contents
- Quick answer
- Mistake 1: tidying the printout and losing the header
- Mistake 2: expecting NULL to become an empty cell
- Mistake 3: blaming the converter for unquoted commas
- Mistake 4: pipe characters inside values
- Mistake 5: values that genuinely start or end with spaces
- The missing summary line is not lost data
- How to check a converted file before trusting it
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Most SQL to CSV surprises come from five causes. The header or border lines were tidied away before pasting, so the columns were read wrongly. NULL was copied as the literal word NULL, which is the honest behaviour. A value containing a comma was opened without the double quotes CSV requires around such fields. A pipe character inside a value split its row, because the parser splits on every |. And the summary line at the bottom was removed deliberately, because it is commentary, not data. The SQL to CSV Formatter is predictable once these rules are known.
Mistake 1: tidying the printout and losing the header
The border lines, separator lines and header row of a printed table look like decoration, so people delete them before pasting and keep only the neat rows. That removes the very information the formatter uses to find the columns and name them. Paste the output exactly as the client printed it, header and borders included, and let the converter do the tidying. If the printout was borderless and the preview shows the first data row treated as the header, or the header merged into the data, pick the format yourself instead of relying on Auto-detect and convert again.
Mistake 2: expecting NULL to become an empty cell
When a query result contains a null, the client prints the text NULL. That text is all the formatter sees, and it copies it faithfully: the CSV cell contains the word NULL, not an empty value. This is deliberate. Silently replacing it with an empty cell would be a guess about your convention, and in some datasets the word NULL is real data. If your spreadsheet or import expects empty cells for missing values, find and replace NULL after downloading, as a conscious step you control.
Mistake 3: blaming the converter for unquoted commas
CSV has one rule that catches everyone: a field that contains a comma must be enclosed in double quotes, or the comma is read as a column separator and the row shifts sideways when the file opens. This is a property of the CSV format itself, described in RFC 4180, not a quirk of any one tool. If a converted file opens with ragged columns, open it in a text editor and look at the raw lines: a value such as an address or a name written as Smith, John needs to appear as "Smith, John" in the file. Checking the raw text separates format problems from data problems.
Mistake 4: pipe characters inside values
In a MySQL ASCII table, the | character is the column border. The parser therefore splits each row on every pipe it finds, and it cannot know that a pipe inside a notes field was meant as punctuation. A value such as called | emailed turns one row into extra columns, wider than the header. The fix is at the source: remove or replace pipe characters in your values before printing, or export that particular result in a tab or semicolon delimited format instead of a bordered table.
Mistake 5: values that genuinely start or end with spaces
Printed tables pad every cell with spaces so the columns line up. Conversion trims that padding, because there is no way to distinguish deliberate spaces from presentation spaces. A code stored as 042 with meaningful leading spaces comes out as 042. For names, numbers and ordinary text this never matters; for padded codes and fixed-width identifiers it does, so check one such value in the preview before you rely on the file.
The missing summary line is not lost data
Terminal clients end a result with a line such as (3 rows). It feels like part of the output, so its absence from the CSV looks like a lost row. It is removed deliberately: the line is the client commenting on the result, not a record in it, and converting it would add a broken extra row to every file. If you want proof that nothing was lost, count the data rows in the printout and in the CSV and compare, ignoring the summary line entirely.
How to check a converted file before trusting it
Three quick checks catch everything. First, compare the data row count before and after. Second, confirm every row has the same number of fields as the header; a wider row points at a pipe or an unquoted comma. Third, spot-check one NULL and one long text value against the printout. If a check fails, adjust at the source or change the format choice, and convert again.
Limitations and honest tradeoffs
The formatter reads text, and text loses information. It cannot know whether NULL was a database null or a literal string your data contains, whether spaces were padding or content, or whether a pipe was a border or punctuation. It applies one consistent rule to each case, which is the most any converter of printouts can honestly do. It also never runs SQL and has no database connection, so it cannot re-query for a cleaner export; if a result is truly pipe-ridden, a delimited printout from your client is the better input.
Common mistakes
- Deleting the header or border lines before pasting. They are the column map; paste the printout exactly as printed.
- Reading literal NULL cells as a bug. The formatter copies the printed text honestly; replace it afterwards if your convention is empty cells.
- Opening a ragged CSV only in a spreadsheet. Check the raw text in an editor to see whether comma-bearing fields are quoted.
- Storing pipes in values and expecting bordered tables to survive. Split happens on every
|; use a delimited format for such data. - Counting the summary line as a data row. It is removed on purpose; compare data row counts instead.
FAQs
Why does my spreadsheet show the word NULL instead of empty cells? Because the printed output only ever contained the text NULL, and the formatter copies it as the printed literal text. Inventing an empty cell would be a guess about what you wanted. If your convention is empty cells for missing data, find and replace NULL after downloading.
Why did one row gain extra columns? A value in that row contained a pipe character. In an ASCII table the pipe is the column border, so the parser splits on every pipe it finds, including the ones inside values. Re-export that result in a delimited format, or remove the pipes from the values first.
Why does a value with a comma break my columns when I open the file? That is a CSV rule, not a conversion fault: a field containing a comma has to be enclosed in double quotes, or a spreadsheet reads the comma as a column separator. Open the CSV in a text editor and check that comma-bearing fields are quoted before blaming the data.
Where did the row count line at the bottom go? Summary lines such as (3 rows) are removed deliberately. They are the client commenting on the result, not a data row, and keeping one would add a broken extra record to the CSV. Count the data rows before and after converting if you want to confirm nothing was lost.
Why did the spaces at the start of my codes disappear? Cell padding is trimmed during conversion, and a value that genuinely starts or ends with spaces cannot be told apart from presentation padding. The spaces are removed along with it, which matters only if your data stores meaningful leading or trailing spaces.
Conclusion
A converted file that looks wrong is usually a printout rule you had not met yet, not damaged data. Keep the header and borders when you paste, expect NULL as text, watch for pipes and unquoted commas, and let the summary line go. The SQL to CSV Formatter will then produce the same clean result every time. For the full workflow this troubleshooting supports, see our companion guide on how to format SQL output as CSV for a report. For more in this series, see the Data and JSON Tools guides.
References
- RFC 4180, the memo describing the CSV format and its quoting rules: https://www.rfc-editor.org/rfc/rfc4180
- MySQL Reference Manual, on the mysql client and its output: https://dev.mysql.com/doc/refman/8.0/en/mysql.html