Generador de SQL INSERT
Convierte datos CSV en sentencias SQL INSERT para poblamiento rápido de bases de datos
Converting CSV Data to SQL INSERT Statements
Populating databases with test data, migrating between systems, or seeding initial records often starts with tabular data in CSV format. Manually writing INSERT statements for hundreds of rows is tedious and error-prone — missing quotes around strings, incorrect value ordering, or unescaped special characters cause insertion failures. The SQL INSERT Generator transforms CSV data into syntactically correct INSERT statements with proper quoting, escaping, and batch support for MySQL, PostgreSQL, and SQLite dialects.
Paste your CSV data (with headers), select your target database dialect and table name, and receive ready-to-execute INSERT statements. The tool handles string quoting, NULL value detection, numeric type inference, and special character escaping automatically. For large datasets, batch mode generates multi-row INSERT syntax that executes significantly faster than individual statements.
Dialect-Specific SQL Generation
Each database dialect has different quoting and syntax requirements:
- MySQL: Backtick-quoted identifiers, single-quoted strings,
\escape character, supports multi-row INSERT - PostgreSQL: Double-quoted identifiers (when needed), single-quoted strings,
''escape for quotes, supports multi-row INSERT with RETURNING - SQLite: Double-quoted identifiers, single-quoted strings, limited multi-row INSERT (uses UNION ALL fallback for older versions)
The generator detects special characters in values and applies appropriate escaping for each dialect, preventing SQL injection vulnerabilities in the generated output.
Type Inference and NULL Handling
The tool infers column types from CSV values to apply correct SQL formatting:
- Integers: Values matching
^-?\d+$are inserted without quotes - Floats: Values matching decimal patterns are inserted as numeric literals
- Booleans: "true"/"false", "yes"/"no", "1"/"0" converted to dialect-appropriate boolean syntax
- NULL values: Empty cells, "null", "NULL", "\N" converted to SQL NULL keyword
- Strings: All other values receive proper quoting with special character escaping
Type inference can be overridden by forcing all values to string type for columns where numeric-looking data should remain quoted (like phone numbers or zip codes).
Batch Insert Optimization
For large datasets, the generator supports batch INSERT syntax that dramatically improves insertion performance:
- Multi-row VALUES:
INSERT INTO t VALUES (row1), (row2), (row3);— reduces round-trips and transaction overhead - Configurable batch size: Group rows into batches of 100, 500, or 1000 to balance memory usage and performance
- Transaction wrapping: Optional BEGIN/COMMIT wrapping around batches for atomicity
- ON CONFLICT handling: PostgreSQL UPSERT syntax (
ON CONFLICT DO UPDATE) and MySQL equivalent (ON DUPLICATE KEY UPDATE) for idempotent data loading
Multi-row inserts can be 10-50x faster than individual INSERT statements because they reduce parsing overhead, network round-trips, and transaction log writes per row. For very large datasets (10,000+ rows), the generator splits output into multiple batch statements to avoid exceeding database packet size limits (MySQL's max_allowed_packet defaults to 64MB).
Code Examples
CSV to INSERT Statement Conversion
-- Input CSV:
-- name,email,age,active
-- Alice,alice@example.com,30,true
-- Bob,bob@example.com,,false
-- "O'Brien",obrien@test.com,45,true
-- Generated SQL (PostgreSQL):
INSERT INTO users (name, email, age, active) VALUES
('Alice', 'alice@example.com', 30, TRUE),
('Bob', 'bob@example.com', NULL, FALSE),
('O''Brien', 'obrien@test.com', 45, TRUE); Preguntas Frecuentes
What input format does the SQL INSERT generator accept?
The generator accepts CSV (comma-separated values) with headers in the first row. Column names from the header become the INSERT column list, and each subsequent row becomes a VALUES clause. The tool handles proper quoting and escaping of string values.
Does it support batch INSERT statements?
Yes. You can choose between individual INSERT statements (one per row) or batch mode that groups multiple rows into a single INSERT with multiple VALUES clauses. Batch mode is more efficient for bulk data loading as it reduces round-trips to the database.
How are special characters and NULL values handled?
String values are automatically escaped (single quotes are doubled). Empty CSV fields can be treated as NULL or as empty strings depending on your configuration. Numeric values are inserted without quotes when detected automatically.