Basic Syntax
Create Single Record
| Database | Output |
|---|---|
| PostgreSQL | INSERT INTO users (name, email, age) VALUES ('John', '[email protected]', 30) |
| MySQL | INSERT INTO users (name, email, age) VALUES ('John', '[email protected]', 30) |
| MongoDB | db.users.insertOne({ name: 'John', email: '[email protected]', age: 30 }) |
| Redis | HMSET users:1 name "John" email "[email protected]" age 30 |
Data Types
Multiple Fields
With Timestamps
Bulk Insert
Insert multiple records at once. Each record is wrapped in square brackets with= assignments.
| Database | Output |
|---|---|
| PostgreSQL | INSERT INTO users (name, age) VALUES ('Alice', 25), ('Bob', 30), ('Charlie', 35) |
| MySQL | INSERT INTO users (name, age) VALUES ('Alice', 25), ('Bob', 30), ('Charlie', 35) |
| MongoDB | db.users.insertMany([{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]) |
Upsert
Insert or update if exists. Specify conflict field(s) withON.
| Database | Output |
|---|---|
| PostgreSQL | INSERT INTO users (...) ON CONFLICT (email) DO UPDATE SET name = 'John Updated', login_count = 1 |
| MySQL | INSERT INTO users (...) ON DUPLICATE KEY UPDATE name = 'John Updated', login_count = 1 |
| MongoDB | db.users.updateOne({ email: '[email protected]' }, { $set: { ... } }, { upsert: true }) |
Upsert with Composite Key
Replace
Delete and insert (MySQL-specific behavior).| Database | Output |
|---|---|
| PostgreSQL | Uses UPSERT behavior |
| MySQL | REPLACE INTO users (id, name, email) VALUES (...) |
| MongoDB | db.users.replaceOne({ _id: 1 }, { ... }) |

