Last updated
Example: Individual INSERT Statements
// Same input, individual statements:
INSERT INTO users (id, name, email, age) VALUES (1, 'Alice', 'alice@example.com', 30);
INSERT INTO users (id, name, email, age) VALUES (2, 'Bob', 'bob@example.com', 25);
INSERT INTO users (id, name, email, age) VALUES (3, 'Carol', 'carol@example.com', 35);
Example: MySQL Dialect
// Input JSON:
[
{ "id": 1, "name": "Widget A", "price": 9.99, "active": true, "description": null },
{ "id": 2, "name": "Widget B", "price": 14.99, "active": false, "description": "Premium widget" }
]
-- Generated SQL (MySQL):
INSERT INTO products (`id`, `name`, `price`, `active`, `description`) VALUES
(1, 'Widget A', 9.99, 1, NULL),
(2, 'Widget B', 14.99, 0, 'Premium widget');
-- Note: MySQL uses backtick quoting and 1/0 for booleans
Example: SQL Server Dialect
-- Generated SQL (SQL Server):
INSERT INTO [products] ([id], [name], [price], [active], [description]) VALUES
(1, N'Widget A', 9.99, 1, NULL),
(2, N'Widget B', 14.99, 0, N'Premium widget');
-- Note: SQL Server uses bracket quoting and N'' prefix for Unicode strings
Example: Special Characters Escaping
// Input JSON:
[
{ "id": 1, "name": "O'Brien", "note": "He said \"hello\"" },
{ "id": 2, "name": "Smith & Jones", "note": "100% complete" }
]
-- Generated SQL (escaped):
INSERT INTO contacts (id, name, note) VALUES
(1, 'O''Brien', 'He said "hello"'),
(2, 'Smith & Jones', '100% complete');
-- Single quotes in strings are escaped as '' (SQL standard)
Example: CREATE TABLE + INSERT
// Input JSON:
[
{ "id": 1, "username": "alice", "email": "alice@example.com", "score": 98.5, "active": true, "createdAt": "2024-01-15T14:30:00Z" }
]
-- Generated SQL (with CREATE TABLE):
CREATE TABLE users (
id INTEGER NOT NULL,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
score DECIMAL(10,2),
active BOOLEAN,
created_at TIMESTAMP,
PRIMARY KEY (id)
);
INSERT INTO users (id, username, email, score, active, created_at) VALUES
(1, 'alice', 'alice@example.com', 98.5, TRUE, '2024-01-15T14:30:00Z');
Example: UPSERT (Insert or Update)
// Input JSON:
[
{ "id": 1, "name": "Alice", "email": "alice@example.com" },
{ "id": 2, "name": "Bob", "email": "bob@example.com" }
]
-- PostgreSQL UPSERT:
INSERT INTO users (id, name, email) VALUES
(1, 'Alice', 'alice@example.com'),
(2, 'Bob', 'bob@example.com')
ON CONFLICT (id) DO UPDATE SET
name = EXCLUDED.name,
email = EXCLUDED.email;
-- MySQL UPSERT:
INSERT INTO users (id, name, email) VALUES
(1, 'Alice', 'alice@example.com'),
(2, 'Bob', 'bob@example.com')
ON DUPLICATE KEY UPDATE
name = VALUES(name),
email = VALUES(email);
-- SQLite UPSERT:
INSERT OR REPLACE INTO users (id, name, email) VALUES
(1, 'Alice', 'alice@example.com'),
(2, 'Bob', 'bob@example.com');
Example: Nested JSON as JSON Column
// Input JSON:
[
{
"id": 1,
"name": "Alice",
"preferences": { "theme": "dark", "language": "en", "notifications": true }
}
]
-- Generated SQL (nested object stored as JSON string):
INSERT INTO users (id, name, preferences) VALUES
(1, 'Alice', '{"theme":"dark","language":"en","notifications":true}');
-- PostgreSQL with JSONB column:
INSERT INTO users (id, name, preferences) VALUES
(1, 'Alice', '{"theme":"dark","language":"en","notifications":true}'::jsonb);
Example: Batch Size Configuration
// 1000 records, batch size 100:
-- Batch 1 (rows 1-100):
INSERT INTO orders (id, product, amount) VALUES
(1, 'Widget A', 9.99),
(2, 'Widget B', 14.99),
-- ... 98 more rows
(100, 'Widget C', 4.99);
-- Batch 2 (rows 101-200):
INSERT INTO orders (id, product, amount) VALUES
(101, 'Widget D', 19.99),
-- ... 99 more rows
(200, 'Widget E', 7.99);
-- ... 8 more batches
Dialect Comparison
Feature PostgreSQL MySQL SQL Server SQLite
─────────────────────────────────────────────────────────────────
String quotes 'value' 'value' N'value' 'value'
Column quotes "column" `column` [column] "column"
Boolean true TRUE 1 1 1
Boolean false FALSE 0 0 0
Null NULL NULL NULL NULL
Multi-row INSERT Yes Yes Yes Yes (3.7.11+)
Upsert syntax ON CONFLICT ON DUPLICATE MERGE INSERT OR REPLACE
Paste your JSON array, select your target database dialect, and get ready-to-execute INSERT statements. Use the CREATE TABLE option to generate the full setup script including table creation.
Example: Basic INSERT (PostgreSQL)
// Input JSON:
[
{ "id": 1, "name": "Alice", "email": "alice@example.com", "age": 30 },
{ "id": 2, "name": "Bob", "email": "bob@example.com", "age": 25 },
{ "id": 3, "name": "Carol", "email": "carol@example.com", "age": 35 }
]
-- Generated SQL (PostgreSQL):
INSERT INTO users (id, name, email, age) VALUES
(1, 'Alice', 'alice@example.com', 30),
(2, 'Bob', 'bob@example.com', 25),
(3, 'Carol', 'carol@example.com', 35);