Parse Multi-Row INSERT INTO VALUES Syntax
Convert SQL INSERT statements using multi-row VALUES syntax — INSERT INTO table VALUES (...), (...), (...) — into properly formatted CSV rows.
Detailed Explanation
Multi-Row VALUES — The Compact INSERT Format
Modern SQL databases support inserting multiple rows in a single INSERT statement using comma-separated value tuples. This is more efficient than individual INSERT statements and is the default output format for tools like pg_dump and mysqldump.
Example SQL
INSERT INTO inventory (sku, product_name, quantity, unit_price, warehouse) VALUES
('SKU-001', 'Widget A', 500, 4.99, 'West'),
('SKU-002', 'Widget B', 1200, 3.49, 'East'),
('SKU-003', 'Gadget C', 75, 29.99, 'West'),
('SKU-004', 'Gadget D', 200, 19.99, 'East'),
('SKU-005', 'Component E', 3000, 0.99, 'Central');
Generated CSV
sku,product_name,quantity,unit_price,warehouse
SKU-001,Widget A,500,4.99,West
SKU-002,Widget B,1200,3.49,East
SKU-003,Gadget C,75,29.99,West
SKU-004,Gadget D,200,19.99,East
SKU-005,Component E,3000,0.99,Central
Parsing Details
The parser handles multi-row inserts by:
- Locating the
VALUESkeyword - Splitting the remainder into individual
(...)tuples at the top parenthesis level - Within each tuple, splitting by commas while respecting quoted strings
- Handling nested parentheses in expressions (though most INSERT values are simple literals)
This means even hundreds of value tuples in a single statement are correctly split into individual CSV rows. The row count is displayed in the info bar above the output panels.
Use Case
Extracting data from pg_dump or mysqldump output files that use extended insert syntax, converting them to CSV for data analysis tools like pandas or R.