SQL to CSV Converter

-- CSV Output --

Quick Access to SQL Tools

Go straight to the SQL utility you need.

How to Use the SQL to CSV Converter

1

Paste your SQL SELECT query results

Paste your SQL SELECT query results.

2

Click Convert

Click Convert.

3

Download the CSV file

Download the CSV file.

SQL to CSV Converter — Get Your Data Into Spreadsheets in Seconds

At some point, every developer or analyst needs to get data out of SQL and into a spreadsheet. Maybe it's a one-time data request from a stakeholder who wants "just a CSV." Maybe you're building a report in Excel that combines database exports with manual annotations. Maybe you're migrating reference data between systems and the receiving end only accepts CSV. Whatever the scenario, the bottleneck is the same: you have SQL INSERT statements and you need a CSV file. This tool converts SQL INSERT statements directly into RFC 4180-compliant CSV, handling quoting, escaping, and delimiter selection.

The conversion preserves data fidelity — strings with commas get properly quoted, NULL values become empty fields, numeric types stay unquoted, and newlines within values are handled correctly. The tool shows both a formatted table preview and the raw CSV text, so you can verify the output before downloading.

Sounds simple enough, but CSV is deceptively complex. The format has no official specification (RFC 4180 is the closest thing, and it's from 2005). Different tools interpret edge cases differently — how NULLs are represented, whether headers are required, what encoding to use, how to handle values that contain the delimiter character. This guide walks through the decisions you'll face and the trade-offs involved.

Choosing the Right Delimiter

The comma is the default delimiter for CSV files, and it works with virtually every tool on the planet. But "default" doesn't always mean "correct." The right delimiter depends on your data and your target system.

Comma (,) is the safe choice for most situations. Excel, Google Sheets, LibreOffice Calc, pandas, and every ETL tool understand comma-delimited files natively. The downside: if your data contains commas — names like "Smith, John", addresses with city/state formatting, or free-text fields — every such value must be wrapped in double quotes to prevent it from splitting across columns. This works, but it increases the file size and makes the raw text harder to read.

Semicolon (;) solves the comma-in-data problem and is the standard in European locales where commas serve as decimal separators. Many European versions of Excel default to semicolon-delimited CSV, and if you send a comma-delimited file to a colleague in Germany, they may get garbled columns. PostgreSQL's COPY command defaults to comma, but MySQL's LOAD DATA defaults to tabs, and Oracle SQL Developer uses semicolons by default. Match your delimiter to the tool chain, not just the data.

Pipe (|) is uncommon enough that it rarely appears in actual data values. This makes it a good choice for data that contains both commas and semicolons — addresses, free-text comments, or product descriptions. The downside: pipe-delimited files are less universally supported. Some older tools require configuration to recognize the pipe delimiter, and you'll need to specify it explicitly when importing.

Tab is ideal for a specific use case: pasting data directly into a spreadsheet without saving a file. If you copy tab-delimited text and paste it into Excel, the columns align automatically. This is great for quick data transfers in chat messages or documents. The downside: tabs are invisible in most text editors, making it hard to verify formatting by looking at the raw text.

Quote Character Handling and RFC 4180 Compliance

RFC 4180 specifies that fields containing the delimiter, double quotes, or newlines must be enclosed in double quotes. Double quotes within the field content are escaped by doubling them: a value containing "hello" becomes """hello""" in the CSV output. This tool follows those rules exactly.

The quoting behavior has implications beyond mere correctness. If your data rarely contains commas, minimal quoting produces cleaner, more readable CSV. If your data frequently contains commas (like a column of addresses), extensive quoting is unavoidable but the file remains machine-readable even if it's ugly in a text editor. There's no way around this — it's a fundamental limitation of the CSV format. Alternatives like TSV (tab-separated) or fixed-width formats avoid the quoting problem but introduce others.

One subtlety: some tools wrap all string values in quotes, even when quoting isn't necessary. This is called "quote all" mode and it simplifies parsing at the cost of larger files. This tool quotes only when required by the data content, which produces more compact output. If you need "quote all" behavior for a specific import tool, you'd need to post-process the CSV output.

Another edge case: values that contain both the delimiter and a double quote. A cell containing He said "hello, world" in a comma-delimited CSV becomes "He said ""hello, world""" — the entire value is wrapped in quotes, and each internal quote is doubled. The tool handles this correctly, producing output that any RFC 4180 parser will handle.

NULL Representation: Empty Fields vs. Text Markers

CSV has no concept of NULL. A field is either present (with some content, possibly empty) or the field itself doesn't exist (which would mean fewer columns than expected). The tool outputs SQL NULL as an empty field — no text, no marker, no special encoding. This matches how most CSV parsers and spreadsheet applications handle missing data.

But the "empty field" approach has a practical problem: you can't distinguish between NULL (never set) and an empty string (explicitly set to nothing). In SQL, these are different things. INSERT INTO users (name) VALUES ('') stores an empty string; INSERT INTO users (name) VALUES (NULL) stores NULL. Both produce an empty cell in CSV. If your downstream process needs to distinguish them, you'll need to replace NULLs with a sentinel value in the SQL before converting — something like COALESCE(name, 'N/A') — or handle the ambiguity in your import logic.

Some organizations adopt conventions for NULL representation: using the literal text NULL, N/A, -, or EMPTY in place of null values. If your team has such a convention, preprocess the SQL with COALESCE or CASE expressions before conversion. The converter faithfully outputs whatever value appears in the INSERT statement, so the NULL representation is entirely under your control.

Handling Large Result Sets and Streaming

When your SQL data is small — a few hundred rows — the conversion is instantaneous and you don't need to think about performance. But what happens when you have 50,000 rows of INSERT statements? Or 200,000? The browser has to parse the SQL, convert each row to CSV format, concatenate the entire output, and render a preview table. That's a lot of memory.

This tool handles moderate datasets (up to several thousand rows) without issues. For larger datasets, the browser may become sluggish during conversion or when rendering the preview table. The practical workaround is to split your SQL into chunks — most database export tools let you control the batch size. Export 5,000 rows at a time, convert each batch, and concatenate the CSV files. The header row should appear only in the first file if you're concatenating.

For genuinely massive datasets (hundreds of thousands of rows or more), you're better off using a server-side approach: pg_dump for PostgreSQL, mysqldump for MySQL, or a custom script that streams rows directly to a file. The browser-based approach has inherent memory limitations that no amount of JavaScript optimization can overcome. This tool is designed for convenience and speed on typical datasets, not for processing gigabyte-scale exports.

A practical tip for large exports: if you're converting data for a one-time import into another system, check whether that system can import directly from SQL. PostgreSQL's COPY command, MySQL's LOAD DATA INFILE, and SQLite's .import command all accept SQL-like formats directly, bypassing the need for CSV entirely.

Encoding Considerations for International Data

The tool outputs UTF-8 encoded CSV. This handles virtually all character sets — Latin accents, CJK characters, Arabic, Cyrillic, emoji, and mathematical symbols. UTF-8 is the de facto standard for text encoding in 2024, and any modern tool will handle it correctly.

The exception is Microsoft Excel on Windows. Excel's default CSV import behavior interprets files as ANSI (system locale encoding), not UTF-8. When you open a UTF-8 CSV file in Excel by double-clicking, non-ASCII characters get garbled. The workaround: use Data > From Text/CSV and select "65001: Unicode UTF-8" as the file origin. Alternatively, save the file with a .csv extension but prefix it with a UTF-8 BOM (Byte Order Mark). The BOM is three bytes (EF BB BF) at the start of the file that tell Excel to treat the content as UTF-8.

Google Sheets, LibreOffice Calc, and macOS Numbers all handle UTF-8 automatically without a BOM. If your primary audience uses these tools, encoding is a non-issue. If you're targeting Excel users on Windows, either add the BOM or instruct them to use the explicit import dialog.

Legacy systems that expect ASCII or Latin-1 encoding are becoming rare, but they exist. If you need to convert UTF-8 output to Latin-1, you can use a tool like iconv or a text editor's encoding conversion feature. Be aware that Latin-1 can't represent characters outside the Latin alphabet — Chinese, Japanese, Arabic, and other scripts will be lost in conversion.

Header Row Decisions: When to Include and When to Skip

The header row contains column names extracted from your CREATE TABLE definition or the INSERT column list. Including headers makes the CSV self-documenting — anyone who opens the file can immediately understand what each column represents. Excluding headers produces a "pure data" file that's suitable for automated import where the receiving system already knows the column mapping.

Include headers when: the CSV is going to a human (stakeholder, analyst, manager), it's being opened in a spreadsheet for manual review, or it's a standalone export that needs to be self-explanatory. Exclude headers when: you're appending multiple exports to the same file (duplicate headers would break parsers), the receiving system specifies "headerless" import, or you're piping the CSV directly into a database import command that already has the column mapping configured.

One common workflow: export multiple tables from the same database as separate CSV files, each with headers, and combine them in a spreadsheet on different sheets. Another workflow: export the same table multiple times (daily snapshots, for example) without headers and concatenate them into a single growing file for time-series analysis. The header toggle accommodates both patterns.

Tips for Spreadsheet Import

Number formatting: Leading zeros in numeric values (like ZIP codes 02134 or phone numbers 07700 900123) get stripped by spreadsheet applications that interpret them as numbers. If leading zeros matter, you need to either format the SQL values as strings (wrap in quotes: '02134') or format the target column as text before importing. By the time Excel has parsed the CSV and converted the column, the zeros are already gone. Date formats: Dates exported as SQL strings (like 2024-01-15) are usually auto-parsed by spreadsheets into their internal date representation. This is usually fine, but edge cases exist. Excel interprets 1/2/2024 as January 2nd in US format and February 1st in European format, depending on your system locale. ISO 8601 format (2024-01-15) avoids this ambiguity because it's unambiguous. Large datasets: Excel caps at 1,048,576 rows. Google Sheets caps at 10 million cells (which is fewer rows than you think if you have many columns). Plan your batch sizes accordingly if the target is a spreadsheet application.

Precision loss: Excel stores numbers with 15 digits of precision. SQL's DECIMAL(20,4) or NUMERIC types can hold more. If your data has more than 15 significant digits, Excel will silently truncate or round the values. For high-precision data, import the CSV with the column formatted as text to preserve exact values. Formula injection: If your data contains strings that start with =, +, -, or @, Excel may interpret them as formulas. This is a known security concern (CSV injection). The tool doesn't add any special handling for this — be aware that importing untrusted CSV data into Excel can execute unintended calculations.

Common Export Scenarios

Stakeholder requests: "Can you send me a spreadsheet of all active users?" You could query the database and export from your client, but if you've got the data as INSERT statements from a migration or seed file, this tool skips the database connection entirely. No need to find the right credentials, connect to a VPN, or request temporary access. Data migration between systems: Moving from one CRM to another, one CMS to another — the target system often provides a CSV import tool but not a SQL import tool. Convert your SQL dump to CSV and import. Audit and compliance: Generating CSV snapshots of configuration tables, permission records, or access logs for periodic review by teams that live in spreadsheets. Backup verification: Export critical lookup tables as CSV and compare them against known good values using a diff tool or spreadsheet VLOOKUP. Testing data: Creating test data files for spreadsheet-based testing workflows or data-driven test suites that read from CSV.

Frequently Asked Questions

The tool processes CREATE TABLE + INSERT INTO ... VALUES combinations. Column names come from either the CREATE TABLE definition or explicit INSERT column lists. Multiple INSERT statements for the same table, and multiple VALUES rows per INSERT, are all merged into a single CSV output. SELECT queries are not supported — this tool converts SQL data statements, not query results. If you have SELECT output (like from a pg_dump or mysqldump), convert it to INSERT format first.
Yes. The output follows RFC 4180 — the formal specification for CSV format. Fields containing the delimiter character, double quotes, or newlines are wrapped in double quotes. Any double quotes within the field content are escaped by doubling them. Unicode characters are preserved as UTF-8. This ensures the output can be parsed by any standards-compliant CSV reader, including Excel, Google Sheets, pandas, and R's read.csv.
Comma is the standard and works with virtually every tool. Semicolon is common in European locales where commas are decimal separators. Pipe is useful when your data contains commas frequently — it reduces the amount of field quoting needed, producing cleaner output. Tab-delimited files are ideal when you want to paste data directly into a spreadsheet without saving a file first. Match the delimiter to whatever the receiving system expects; when in doubt, comma is almost always safe.
The tool outputs UTF-8 encoded CSV. Excel on Windows may interpret this as ANSI unless you explicitly choose UTF-8 during import (Data > From Text/CSV > File Origin: 65001: Unicode UTF-8). Alternatively, download the file and open it in LibreOffice Calc or Google Sheets, which handle UTF-8 automatically. For a quick workaround in Excel, you can rename the file from .csv to .txt, open it, and use the Text Import Wizard with UTF-8 encoding selected. Adding a UTF-8 BOM to the file beginning also forces Excel to recognize the encoding.
SQL NULL values are output as empty CSV fields — nothing between the delimiters. This is the standard way CSV handles missing data. Most spreadsheet and analysis tools interpret empty cells as null/missing. If you need a specific text representation (like "N/A" or "NULL"), replace the values in your SQL using COALESCE before converting. The converter faithfully outputs whatever value is in the INSERT statement, so you have full control over NULL representation.
There's no hard limit in the converter itself — performance depends on your browser's available memory. Thousands of rows process in seconds. For very large datasets (tens of thousands of rows or more), consider splitting your SQL into smaller batches of 5,000 rows to avoid browser performance issues. Also keep in mind that Excel has a 1,048,576 row limit and Google Sheets caps at 10 million cells, so plan your batch sizes accordingly if the target is a spreadsheet application.
Yes. The tool has a toggle to include or exclude the header row. Include headers when the CSV is meant for human consumption in a spreadsheet — they provide column labels that make the data self-documenting. Exclude headers when importing into another system that already knows the column mapping, or when concatenating multiple CSV exports where duplicate headers would break the import parser.
The download button creates a .csv file with the correct MIME type, which most applications open automatically when you double-click it. The raw text display lets you inspect the CSV content and copy it directly to your clipboard — useful if you want to paste it into a text editor, a terminal command, or another tool without creating a file. Both produce the same CSV data; the delivery method differs. Copying raw text is also useful when you want to paste directly into a spreadsheet cell.
Yes. The tool outputs UTF-8, which encodes multi-byte characters correctly — including accented Latin characters, CJK ideographs, Arabic script, Cyrillic, and emoji. The byte count of the CSV output will be larger than the character count for multi-byte characters, but the data integrity is preserved. Any modern tool that reads UTF-8 CSV will handle these characters without issues. The one exception remains Excel on Windows, which may need the UTF-8 BOM or explicit encoding selection during import.