UPDATE

The UPDATE statement overwrites the values of map entries that match the condition in a given WHERE clause. However, you cannot update keys in map entries.

This statement is not atomic. If it fails, a part of the rows might be updated and another part might remain unchanged.

Syntax Summary

This code block is a quick reference with all the parameters that you can use with the UPDATE statement.

See some practical examples.

UPDATE table_name [ [ AS ] alias ]
SET { column_name = expression } [, ...]
[ WHERE condition ]

Parameters

The UPDATE statement accepts the following required parameters.

Parameter Description Example

column_name

The name of column to set value for.

expression

The value to assign. Can be a literal, parameter, or an expression from other column’s values.

WHERE condition

An optional clause that, if given, indicates the conditions that rows must satisfy to be updated. condition is an expression that is evaluated for each row. If the expression is true, the row is selected. If there’s no WHERE clause, all rows are updated.

Examples

This section lists some example SQL queries that show you how to use the UPDATE statement.

Update Columns by Name

You can overwrite the values in columns by name, using the SET clause.

For example, in a map that contains Employee objects as values with the following structure:

Name

Type

startDate

INT

amount

INT

title

VARCHAR

department

VARCHAR

You can update the values of the Employee.department field:

UPDATE employees
SET department = 'engineering'
WHERE title LIKE '%developer%';

Whether you can access nested fields like this in objects depends on how your map entries are serialized: