You ran the query, the results look right in the terminal, and then you paste them into a spreadsheet and get a mess: border lines of plus signs and dashes, every value padded with spaces, and a summary line announcing the row count. None of that is data, but all of it has to go before the file is useful to anyone else.

The good news is that this cleanup is not a manual editing job. The SQL to CSV Formatter on Ovatly rescues exactly this kind of output: it strips the borders, padding and summary lines during conversion and hands you a clean file called query-result.csv. What conversion cannot do is make three judgement calls for you: format detection, NULL values, and pipes hiding inside your data.

Contents

  • Quick answer
  • What raw terminal output actually contains
  • The cleanup happens during conversion
  • Check one: the format detection
  • Check two: NULL values arrive as literal text
  • Check three: pipes inside values break ASCII parsing
  • How to clean up database output, step by step
  • Worked example: a MySQL table becomes a CSV
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Copy the complete text output of your query and paste it into the SQL to CSV Formatter. Let it auto-detect the format, or pick the format yourself if the columns look wrong. Convert, then download query-result.csv. The borders, padded spacing and row-count summary are removed by the conversion itself. Before sharing the file, make three checks: confirm the detected format, scan for NULL values, and check whether any value contains a pipe character.

What raw terminal output actually contains

A database client prints results for human eyes, not for other software. A MySQL result arrives as an ASCII table: a border line of +---+ segments above and below, headers in their own row, and every cell padded with spaces. psql underlines its headers with a dashed separator instead. Both add a summary at the end, such as (3 rows).

Every one of those elements is presentation, not content. Pasted raw into a spreadsheet, the borders become rows, the padding becomes part of every value, and the summary becomes a stray line. Cleaning up means removing the presentation while keeping the content exactly as queried.

The cleanup happens during conversion

This is where most people go wrong: they open the pasted output in a text editor and start deleting border lines by hand, row by row. That is slow, and one careless find-and-replace can eat real data.

The formatter does the whole cleanup as a side effect of converting. It recognises the structure, reads the header and data rows out of it, and writes plain CSV: no border lines, no alignment padding, and summary lines such as (3 rows) removed deliberately, because they were never data. What lands in query-result.csv is one header line and one line per row.

Check one: the format detection

The formatter auto-detects what you pasted, and it can also be told. The formats it understands are MySQL ASCII tables with +---+ borders, psql output with dashed separators, whitespace-aligned columns with a dashed separator, tab or semicolon delimited text, and a fallback that splits on two or more spaces.

Auto-detect occasionally guesses wrong, most often with whitespace-aligned output, where a value containing a double space can look like a column break. The symptom is easy to spot: columns shifted, headers split, or two fields fused into one. When that happens, do not re-paste or edit the text. Pick the format manually and convert again; it tells the formatter exactly which structure to read.

Check two: NULL values arrive as literal text

When a query result contains a NULL, the terminal prints the word NULL, and the formatter copies it into the CSV as literal text. It does not convert it to an empty cell, and it does not drop the row.

That leaves a decision with you. Some import tools treat the text NULL as a string value, which is probably not what you want in a numeric column; others expect genuinely empty cells. Before exporting, search the file for NULL and decide, column by column, whether the text stays or gets cleared.

Check three: pipes inside values break ASCII parsing

A MySQL ASCII table separates columns with the pipe character |. That works until a value itself contains a pipe, for example a notes field where someone typed options separated by pipes. The formatter splits on every pipe, so a pipe inside a value is indistinguishable from a column boundary, and that row comes out with extra columns.

No setting fixes this, because the ambiguity is in the pasted text itself. Spot-check rows with long text values, or re-run the query with a different output style, such as tab-delimited, and paste that instead. If a converted row has more fields than the header, a pipe inside a value is the first suspect.

How to clean up database output, step by step

  1. Run your query and copy the complete text output, including borders and summary line. The SQL to CSV Formatter expects the raw output as printed.
  2. Paste it in, leaving auto-detect on for a first pass.
  3. Convert and inspect the result. Count the columns against your headers; if they are shifted or fused, pick the format manually and convert again.
  4. Scan for NULL text and decide whether each occurrence stays as text or becomes an empty cell.
  5. If you pasted an ASCII table, check any row with more fields than the header for a pipe inside a value.
  6. Download query-result.csv and confirm it opens cleanly in your spreadsheet.

Worked example: a MySQL table becomes a CSV

Suppose a query returns two customers, printed as a MySQL ASCII table:

+----+------+
| id | name |
+----+------+
| 1  | Ana  |
| 2  | Ben  |
+----+------+

Converted, the borders, cell padding and row-count summary are gone. The downloaded file contains exactly this:

id,name
1,Ana
2,Ben

That is the entire cleanup: the values are unchanged, and everything that existed only for readability is gone.

Limitations and honest tradeoffs

The formatter converts text you paste; it never runs SQL and never connects to your database, so it cannot re-run a query. If your client truncated the output, the CSV is truncated too.

Trimming is a tradeoff, not a pure win. A value that genuinely begins or ends with spaces loses them, because real spaces and alignment spaces are indistinguishable in pasted output. NULL values are copied as literal text rather than interpreted, and pipes inside values break ASCII parsing. When your client can export CSV directly, that route avoids all three costs.

Common mistakes

  • Editing the raw output by hand first. Deleting borders and trimming spaces manually is slow and risks changing values. Paste it raw instead.
  • Trusting auto-detect without looking. A misread format shifts every column. Compare converted columns against the headers before downloading.
  • Forgetting the NULL check. The word NULL lands in your CSV as text. Decide what the receiving system expects first.
  • Blaming the formatter for pipe-split rows. A pipe inside a value looks exactly like a column separator. Re-export in a delimited style instead.
  • Pasting a partial result. If your client paged or truncated the output, the CSV inherits the gap.

FAQs

Does the formatter connect to my database or run my query? No. The tool never runs SQL and makes no database connection. You run your query in your own client, copy the text output, and paste it into the formatter, which converts that text into CSV.

What happens to border lines and the row-count summary? They are removed during conversion. The +---+ borders of a MySQL table, the dashed separator under psql headers, and summary lines such as (3 rows) are stripped deliberately, so the CSV contains only headers and data rows.

Why do my NULL values appear as the word NULL in the CSV? Because the formatter copies NULL as the literal text it was printed as. It does not guess whether you wanted an empty cell instead. If your import expects blanks, replace the NULL text after conversion.

Auto-detect picked the wrong format. What should I do? Pick the format manually instead. The formatter recognises MySQL ASCII tables, psql dashed separators, whitespace-aligned columns with a dashed separator, tab or semicolon delimited text, and a fallback that splits on two or more spaces.

Can the formatter preserve spaces at the start or end of a value? No. Cell padding is trimmed during conversion, so a value that genuinely starts or ends with spaces loses them: in pasted output, alignment spaces and real spaces look identical.

Conclusion

Raw database output is presentation wrapped around data, and the cleanup belongs in the conversion. Paste the output into the SQL to CSV Formatter, let it strip the borders, padding and summary lines, then spend your attention on the three checks only you can make: the format, the NULL values and the pipes. If your data later feeds a conversion chain, our companion guide on validating JSON one more time after any conversion covers the matching final check. For more guides in this series, see our Data and JSON Tools guides.

References