

# UPDATE dbclustergroup\_sys.data\_mappings

Use `UPDATE dbclustergroup_sys.data_mappings` to change the cluster name behind a router name, repoint a collocation, or rename a collocation in a database cluster group for Aurora.

## Description
<a name="databaseclustergroups-sql-update-data-mappings-description"></a>

Changes data mappings: the cluster name behind a router name, the member cluster of a whole collocation, or a collocation's name. A mapping write moves no data. To move a collocation with its data, use [ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-move-collocation.md).

For the task, see [Changing data mappings](databaseclustergroups-changing-mappings.md).

## Syntax
<a name="databaseclustergroups-sql-update-data-mappings-syntax"></a>

```sql
UPDATE dbclustergroup_sys.data_mappings
   SET {{column}} = '{{value}}' [, {{column}} = '{{value}}' ...]
 WHERE { {{column}} = '{{value}}' | ({{column}}, {{column}} [, ...]) = ('{{value}}', '{{value}}' [, ...]) };
```

## Parameters and options
<a name="databaseclustergroups-sql-update-data-mappings-parameters"></a>

For the columns, see [INSERT INTO dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-insert-data-mappings.md).

SET cluster\_db\_name, cluster\_table\_name  
The new cluster names behind a row. The router name stays.

SET member\_cluster\_alias  
The member cluster of the rows. To set it alone, use `WHERE router_collocation_group = '{{collocation}}'` alone, which changes the whole collocation. To move one mapping, set `router_collocation_group` in the same `SET` list.

SET router\_collocation\_group  
The new collocation. Set `member_cluster_alias` in the same statement, unless the `WHERE` clause filters on `router_collocation_group`. Then the statement renames the collocation, or moves the matched rows to a new collocation on the same member cluster.

WHERE  
Required. One equality, or one tuple equality, on any column except `db_cluster_identifier`. Every row that matches changes, so a `WHERE` on a shared value such as `router_collocation_group`, `member_cluster_alias`, or `router_db_name` changes every row with that value. On Aurora MySQL, select one table with `(router_db_name, router_table_name)`.

## Where it runs and required privileges
<a name="databaseclustergroups-sql-update-data-mappings-privileges"></a>

Run the statement where you run every mapping write: at the routing endpoint, in an unpinned session, outside a transaction. For the rules, see [INSERT INTO dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-insert-data-mappings.md#databaseclustergroups-sql-insert-data-mappings-privileges).

The router user needs `dbclustergroup_metadata_admin` or `dbclustergroup_super_admin`. For all privileges for database cluster groups for Aurora, see [Privileges](databaseclustergroups-sql-reference.md#databaseclustergroups-sql-privileges).

## Usage notes
<a name="databaseclustergroups-sql-update-data-mappings-usage"></a>

Keep the following in mind when you use the statement.
+ A mapping change reaches the routing layer within a short time, and a statement routed on an older mapping returns a retryable error. See [Applying data mapping changes](databaseclustergroups-data-mappings.md#databaseclustergroups-when-a-data-mapping-change-takes-effect).
+ Before you repoint a collocation, copy and check every object of the collocation on the target member cluster. A data movement job does this for you.
+ Every row of a collocation is on the same member cluster, so a repoint names the whole collocation. The routing layer refuses a change of `member_cluster_alias` alone for any other `WHERE` clause, even for a row that is alone in its collocation. To move one mapping to its own collocation, set `router_collocation_group` and `member_cluster_alias` together in one `UPDATE`. Check that the number of affected rows matches the collocation's row count.
+ To put a member table of a scaleout table on another member cluster, move its collocation. The routing layer accepts an `UPDATE` of a member table's `cluster_table_name`, and that collocation's reads and writes go to the named table after the change reaches the routing layer.
+ Export the mappings before and after every change. See [Exporting the mappings before and after a change](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings).

One `UPDATE` can change at most 1,000 mappings. A statement whose `WHERE` clause matches more rows fails with error 1235, `Replace of <n> rows exceeds the per-request limit of 1000; narrow the filter or split the write into smaller requests`, and changes nothing. An `UPDATE` that repoints a whole collocation counts as one row, whatever the number of mappings in the collocation. For more information about the limit, see [Routing metadata and naming limits](databaseclustergroups-limitations.md#databaseclustergroups-limitations-routing-metadata-limits).

An `UPDATE` that filters on `router_collocation_group` can set `member_cluster_alias` alone. It moves every data mapping in the collocation group to the new member cluster. To move one data mapping out of its group, set `router_collocation_group` and `member_cluster_alias` together. An `UPDATE` that filters on a single data mapping and sets only `member_cluster_alias` fails with error 64043, because the mappings of a collocation group must stay on one member cluster. This `UPDATE` changes only where the routing layer sends queries; it doesn't move data. Make sure the data is already on the new member cluster before you run it, or use [ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-move-collocation.md) to move the data.

While a data movement job moves a collocation, the routing layer refuses a mapping write that touches the collocation or any object in it, with error 1205 (`Metadata for ... is being changed by another operation`).

A mapping change needs an available writer instance on every member cluster that it affects. This includes both the old and the new member cluster when you repoint a mapping. If one has no available writer, the change fails and nothing changes. The member clusters don't need to be reachable through the routing endpoint, because the routing layer reaches them directly.

## Examples
<a name="databaseclustergroups-sql-update-data-mappings-examples"></a>

The following example repoints the collocation `cg_06` to `member-c`, after its objects are on `member-c`.

```sql
UPDATE dbclustergroup_sys.data_mappings
   SET member_cluster_alias = 'member-c'
 WHERE router_collocation_group = 'cg_06';
```

The following example keeps a router name and points it at a new object on the member cluster.

```sql
UPDATE dbclustergroup_sys.data_mappings
   SET cluster_table_name = 'customers_v2'
 WHERE (router_db_name, router_table_name) = ('app', 'customers');
```

## Errors
<a name="databaseclustergroups-sql-update-data-mappings-errors"></a>

The statement can return the following errors. For the error texts and all errors from the routing layer, see [Routing and data mapping errors](databaseclustergroups-errors-routing.md).


| Aurora MySQL | Meaning | 
| --- | --- | 
| [1227](databaseclustergroups-errors-routing.md) | The router user lacks dbclustergroup\_metadata\_admin. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | The write is inside a transaction. Commit or roll back, and send it again outside a transaction. | 
| [64043](databaseclustergroups-errors-routing.md) (42000) | A change of member\_cluster\_alias alone with a WHERE clause other than router\_collocation\_group alone. Repoint the whole collocation, or set a collocation in the same SET list. | 
| [64066](databaseclustergroups-errors-scaleout.md) (42000) | The mapping is a member table of a scaleout table, and the change would leave a collocation that its routing function targets without a member. | 
| [64062](databaseclustergroups-errors-routing.md) (42000) | The statement sets router\_collocation\_group to an existing collocation on a different member cluster than member\_cluster\_alias. Name a collocation on that member cluster, or a new one. | 
| [64063](databaseclustergroups-errors-routing.md) (42000) | The statement sets router\_collocation\_group without member\_cluster\_alias, and the WHERE clause doesn't filter on router\_collocation\_group. Set both in the same SET list. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | AND/OR are not supported in the WHERE clause on this table: the WHERE clause has more than one condition. Use the tuple form. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | Replace of <n> rows exceeds the per-request limit of 1000; narrow the filter or split the write into smaller requests: your WHERE clause matches more than 1,000 rows, so the statement changes nothing. Narrow the WHERE clause. | 
| [1412](databaseclustergroups-errors-routing.md) (HY000) | After a mapping change, a statement that the routing layer routed on the older mapping returns this error. The routing layer resends a text-protocol statement up to 3 times first, then returns 1412 with the session and any open transaction intact, so retry the statement.  | 
| [63928](databaseclustergroups-errors-routing.md) (40001) | Inside a transaction, a statement needed a mapping that changed after the transaction's first routed statement, and the routing layer rolled the whole transaction back. Retry the whole transaction from its first statement; don't send COMMIT.  | 

## Related statements
<a name="databaseclustergroups-sql-update-data-mappings-related"></a>

For more information, see the following:
+ [SELECT FROM dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-select-data-mappings.md)
+ [INSERT INTO dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-insert-data-mappings.md)
+ [DELETE FROM dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-delete-data-mappings.md)
+ [ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-move-collocation.md)
+ [EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-explain-move-collocation.md)