You ran the query, the results look perfect on screen, and now someone asks for the data as a CSV. So you copy the table out of your terminal, paste it into a spreadsheet, and watch it fall apart: the border characters become columns, every value arrives padded with spaces, and the row count line turns into a junk record. Terminal output is typeset for human eyes, not for machines.

The fix is to convert the printout itself. The SQL to CSV Formatter on Ovatly turns the table your client already printed into a clean CSV file. This guide covers which printout styles it recognises, when to trust auto-detect, and the gotchas worth knowing first.

Contents

  • Quick answer
  • What the tool does, and what it never does
  • The formats it recognises
  • Auto-detect or pick the format yourself
  • How to export SQL query results to CSV, step by step
  • Worked example: a MySQL result becomes a CSV
  • Gotchas: pipes, padding, summary lines and NULL
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Run the query in your own database client and copy the printed result table. Open the SQL to CSV Formatter, paste the output, leave the format on Auto-detect or pick it yourself, click Convert, and download query-result.csv. One point matters more than any other: the tool never connects to a database and never runs SQL. It converts text you paste, locally in your browser, so your credentials and data never leave your machine.

What the tool does, and what it never does

Database clients print results as fixed-width tables because that reads well in a terminal: columns padded with spaces, borders drawn with characters like +, - and |, and a summary line reporting the row count. A CSV reader sees all of that as data. The formatter reads the pasted printout, works out where the columns are, trims the presentation padding, drops the summary lines, and writes clean comma-separated values.

The limits are worth stating plainly, because the name invites the wrong assumption. The tool has no database connection: it cannot run a query, log in to anything, or fetch data for you. The query always happens in your own client, under your own credentials, exactly as it does now; what changes is only the last step. And everything happens locally in your browser, so results containing customer names or email addresses are never uploaded anywhere.

The formats it recognises

Clients print results in a handful of recurring styles, and the formatter handles each:

  • MySQL ASCII tables, with +---+ border lines around the header and the data.
  • psql output, where a line of dashes separates the header from the rows.
  • Whitespace-aligned columns with a dashed separator line, the style several other clients produce.
  • Tab or semicolon delimited text, for output that was already delimited but still needs cleaning into proper CSV.
  • A fallback for anything else: if none of the above match, runs of two or more spaces count as the column separator. The fallback is deliberately simple: it works well on evenly aligned printouts and poorly on ragged ones, which is one reason picking the format yourself sometimes beats auto-detect.

Auto-detect or pick the format yourself

Auto-detect is the right default: the border and separator lines in most printouts make the format obvious. Pick the format manually when it guesses wrong, which usually happens with borderless output. If the preview shows columns merged or split in the wrong places, change the format and convert again; each attempt takes seconds.

How to export SQL query results to CSV, step by step

  1. Run your query in your usual database client and let it print the full result.
  2. Copy the entire printed table, including the border or separator lines: they are how the formatter finds the columns, so do not tidy them away.
  3. Open the SQL to CSV Formatter and paste the output in.
  4. Leave the format on Auto-detect, or pick the format that matches your client.
  5. Click Convert and check the preview: the header row should match your column names, with each value in its own column.
  6. Download query-result.csv and open it in your spreadsheet.

Worked example: a MySQL result becomes a CSV

Suppose a MySQL query returns this printed table:

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

Paste it in, leave the format on Auto-detect, and convert. The downloaded query-result.csv contains exactly this:

id,name
1,Ana
2,Ben

The borders are gone, the padding around Ana and Ben is trimmed, and the header becomes the first CSV row. If the printout ended with a summary line, that line is dropped rather than converted, so it never appears as a stray third record.

Gotchas: pipes, padding, summary lines and NULL

Four behaviours surprise people the first time, and all four are deliberate.

Pipe characters inside values. In an ASCII table, | is the column border, so the parser splits on every pipe it finds. A value that legitimately contains a pipe, such as a notes field reading called | emailed, will split its row into extra columns. Check any row wider than the header, and if pipes are the cause, re-export in a delimited format instead.

Padding is trimmed. A value that genuinely starts or ends with spaces loses them, because deliberate spaces cannot be told apart from presentation padding. Rarely a problem for names, numbers and codes, but worth knowing if you store padded codes.

Summary lines are removed. Lines such as (3 rows) are the client talking about the result, not part of it, so they are deleted on purpose.

NULL stays as text. A null value is copied as the printed literal text, so the cell contains the word NULL. That may not be what your spreadsheet or import expects; if empty cells are the convention, find and replace NULL after downloading.

Limitations and honest tradeoffs

The tool can only be as accurate as the printout you give it. A result copied through a chat window may already have lost its alignment, and no converter can recover columns mangled before pasting. Wide results with many spaces inside values are the hardest case for the fallback separator, so prefer a bordered or delimited printout.

And it bears repeating: this is not an export feature for your database. It never connects and cannot pull data you have not already retrieved yourself.

Common mistakes

  • Pasting the query instead of the results. The formatter converts printed output, not SQL.
  • Deleting the border lines before pasting. They look like clutter, but they are the column map. Paste the output exactly as printed.
  • Trusting the first conversion of a borderless printout. Check the preview against the header; if columns are merged or split wrongly, pick the format manually and convert again.
  • Missing the pipe gotcha. A row with more fields than the header almost always means a value contained a |.
  • Assuming NULL became an empty cell. It arrives as the literal text NULL.

FAQs

Does the tool connect to my database or run my query? No. It has no database connection and it never runs SQL. You run the query in your own client, copy the printed result table, and the tool converts that text into CSV, entirely in your browser.

Which kinds of pasted output does it understand? MySQL ASCII tables with +---+ borders, psql output with dashed separators, whitespace-aligned columns with a dashed separator line, and tab or semicolon delimited text. If none of those match, it falls back to treating two or more spaces as the column separator.

Why did one of my rows split into extra columns? In an ASCII table the pipe character is the column border, so a pipe inside a value is read as another border and the row splits on every pipe. Remove or replace pipe characters in your values, or export that result in a delimited format instead.

What happens to NULL values? NULL is copied as the printed literal text, so the CSV cell contains the word NULL rather than an empty value. If your spreadsheet or import expects empty cells for missing data, find and replace NULL after downloading.

Why did the row count line at the bottom disappear? Summary lines such as (3 rows) are removed deliberately. They are client commentary, not data, and leaving them in would add a broken extra row to the CSV.

Conclusion

Exporting query results to CSV does not need a database connection, a plugin or a hand-built parser. Run the query where you always run it, paste the printed table into the SQL to CSV Formatter, and download the clean file. If your data work starts from configuration files rather than query output, our companion guide on converting TOML to JSON covers the same kind of tidy-up. For more in this series, see the Data and JSON Tools guides.

References