Documentation Index
Fetch the complete documentation index at: https://docs.omniql.com/llms.txt
Use this file to discover all available pages before exploring further.
Modify existing records using the UPDATE operation.
Basic Syntax
:UPDATE Entity SET field:value WHERE condition
Update Single Field
:UPDATE User SET status:"active" WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET status = 'active' WHERE id = 1 |
| MySQL | UPDATE users SET status = 'active' WHERE id = 1 |
| MongoDB | db.users.updateOne({ _id: 1 }, { $set: { status: 'active' } }) |
| Redis | HSET users:1 status "active" |
Update Multiple Fields
:UPDATE User SET name:"John Updated", age:31, updated_at:"2024-01-15T10:30:00Z" WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET name = 'John Updated', age = 31, updated_at = '...' WHERE id = 1 |
| MongoDB | db.users.updateOne({ _id: 1 }, { $set: { name: 'John Updated', age: 31, ... } }) |
Update with Conditions
:UPDATE User SET verified:true WHERE email_confirmed = true AND created_at < "2024-01-01"
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET verified = true WHERE email_confirmed = true AND created_at < '2024-01-01' |
| MongoDB | db.users.updateMany({ email_confirmed: true, created_at: { $lt: '...' } }, { $set: { verified: true } }) |
Bulk Update
Update multiple records matching condition.
:UPDATE Product SET on_sale:true WHERE category = "Electronics"
| Database | Output |
|---|
| PostgreSQL | UPDATE products SET on_sale = true WHERE category = 'Electronics' |
| MongoDB | db.products.updateMany({ category: 'Electronics' }, { $set: { on_sale: true } }) |
Update with IN
:UPDATE User SET role:"premium" WHERE id IN (1, 2, 3, 4, 5)
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET role = 'premium' WHERE id IN (1, 2, 3, 4, 5) |
| MongoDB | db.users.updateMany({ _id: { $in: [1, 2, 3, 4, 5] } }, { $set: { role: 'premium' } }) |
Set to NULL
:UPDATE User SET deleted_at:null WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET deleted_at = NULL WHERE id = 1 |
| MongoDB | db.users.updateOne({ _id: 1 }, { $set: { deleted_at: null } }) |
Increment Values
:UPDATE Product SET quantity = quantity + 10 WHERE id = 1
:UPDATE User SET login_count = login_count + 1 WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE products SET quantity = quantity + 10 WHERE id = 1 |
| MongoDB | db.products.updateOne({ _id: 1 }, { $inc: { quantity: 10 } }) |
Decrement Values
:UPDATE Product SET stock = stock - 1 WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE products SET stock = stock - 1 WHERE id = 1 |
| MongoDB | db.products.updateOne({ _id: 1 }, { $inc: { stock: -1 } }) |
Using Functions
:UPDATE User SET name = UPPER(name) WHERE id = 1
| Database | Output |
|---|
| PostgreSQL | UPDATE users SET name = UPPER(name) WHERE id = 1 |
Complete Examples
Soft Delete
:UPDATE User SET deleted_at:"2024-01-15T10:30:00Z", active:false WHERE id = 1
Deactivate Inactive Users
:UPDATE User SET active:false WHERE last_login < "2023-01-01" AND active = true
Update Order Status
:UPDATE Order SET
status:"shipped",
shipped_at:"2024-01-15T10:30:00Z",
tracking_number:"1Z999AA10123456784"
WHERE id = 1001
Price Adjustment
:UPDATE Product SET price = price * 1.1 WHERE category = "Electronics"
Increases all electronics prices by 10%.
Warning
Always include a WHERE clause to avoid updating all records accidentally.
-- DANGEROUS: Updates ALL users
:UPDATE User SET status:"inactive"
-- SAFE: Updates specific user
:UPDATE User SET status:"inactive" WHERE id = 1
Next Steps
Delete Data
Remove records
Transactions
Group operations