Modify existing database records with flexible filtering and type-safe updates across all supported databases.
The update()
method modifies existing records in database tables. It uses filtering conditions to identify which records to update and applies new values to specified columns. The method returns the number of affected records.
update(table_name: str, filters: Dict[str, Any], new_values: Dict[str, Any]) -> int
Type: str
Name of the table containing records to update. The table must exist.
Type: Dict[str, Any]
Dictionary mapping column names to values for identifying which records to update. Must be non-empty to prevent accidental mass updates.
โ ๏ธ Important: All conditions are combined with AND logic. Empty filters are not allowed for safety.
Type: Dict[str, Any]
Dictionary mapping column names to their new values. Only specified columns will be updated; other columns remain unchanged.
Type: int
Number of records that were actually updated. Returns 0 if no records matched the filter conditions.
Updated 1 user(s) Updated user: {'id': 1, 'username': 'alice', 'email': 'alice@example.com', 'age': 29, 'active': True, 'last_login': '2024-01-15'}
Update multiple records that match the same criteria:
Activated 3 user(s) alice: Active (last login: 2024-01-15) bob: Active (last login: 2024-01-16) charlie: Active (last login: 2024-01-16) diana: Active (last login: 2024-01-16)
Use multiple filter conditions for precise updates:
Applied discount to 1 electronics product(s) Applied discount to 1 book(s) Products with 10% discount: 1 Phone: $699.99 -> $629.99
Update records that reference other tables:
Shipped 1 order(s) Moved 1 order(s) to processing Order 1: $149.99 - shipped Order 2: $299.99 - processing
Uses standard SQL UPDATE statements with WHERE clauses:
Uses MySQL UPDATE syntax with parameter binding:
Uses PostgreSQL UPDATE syntax:
Translates to MongoDB updateMany operation:
Table not found: no such table: nonexistent_table Successfully updated 1 record(s) Error: Filters required for update Table 'missing_table' does not exist
After updating records, you might want to: