Handle SQL NULL Values in CSV Output
Control how SQL NULL values are represented in CSV output. Choose between empty strings, the literal 'NULL', 'null', or 'N/A' for NULL representation.
Data Types
Detailed Explanation
NULL Values — From SQL to CSV
SQL NULL represents the absence of a value, but CSV has no native concept of null. When converting SQL to CSV, you need to decide how to represent missing data. The tool offers four options.
Example SQL
CREATE TABLE contacts (
id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
phone VARCHAR(20),
fax VARCHAR(20),
notes TEXT
);
INSERT INTO contacts VALUES
(1, 'Alice', '+1-555-0100', NULL, 'Primary contact'),
(2, 'Bob', NULL, NULL, NULL),
(3, 'Charlie', '+1-555-0102', '+1-555-0103', NULL);
Output with Different NULL Settings
Empty string (default):
id,name,phone,fax,notes
1,Alice,+1-555-0100,,Primary contact
2,Bob,,,
3,Charlie,+1-555-0102,+1-555-0103,
NULL literal:
id,name,phone,fax,notes
1,Alice,+1-555-0100,NULL,Primary contact
2,Bob,NULL,NULL,NULL
3,Charlie,+1-555-0102,+1-555-0103,NULL
Which Option to Choose
| Setting | Best For |
|---|---|
| Empty string | Spreadsheets (Excel, Google Sheets) |
NULL |
Preserving SQL semantics for reimport |
null |
JSON-style downstream tools |
N/A |
Human-readable reports |
The preview table italicizes NULL representations so you can visually distinguish them from actual empty string values in the data.
Use Case
Preparing data exports where the downstream system (e.g., pandas, R, or a data warehouse loader) requires a specific NULL representation for correct data type inference.