是否可以更改 DynamoDB 表中 Range 键的值?
我知道这可能是一个非常愚蠢的问题,但我是 DynamoDB 的新手.
I know it may be a very silly question, but I am new to DynamoDB.
我怀疑是否可以在 DynamoDB 中更新 Range Key 的值.
My doubt is is it possible to update the value of a Range Key in DynamoDB.
假设我的表是TEST"
Suppose My Table is "TEST"
{
ID : PK/HK
Date : RK
Name : GSI
Add : LSI
}
我要修改Date
属性.
表中的初始值为:
{
ID = "344"
Date = "5656"
Name = "ABC"
}
在下面运行此代码.我可以更改 GSI 的 Name
属性.
Running this code below. I am able to change the Name
Attribute which is GSI.
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
item.put("ID", new AttributeValue("344"));
item.put("Date", new AttributeValue("5656"));
Map<String,AttributeValueUpdate> item1 = new HashMap<String,AttributeValueUpdate>();
AttributeValueUpdate update = new AttributeValueUpdate().withValue(new AttributeValue("AMIT")).withAction("PUT");
item1.put("Name", update);
UpdateItemRequest updateItemreq = new UpdateItemRequest("Test",item,item1);
UpdateItemResult updateItemres = dynamoDBUSEast.updateItem(updateItemreq);
但是当我改变这一行时
item1.put("Name", update);
与
item1.put("Date", update);
我遇到了一些错误
Exception in thread "main" com.amazonaws.AmazonServiceException: One or more parameter values were invalid: Cannot update attribute Date. This attribute is part of the key (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: HRRP24Q7C48AMD8ASAI992L6MBVV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:820)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:439)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:245)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2908)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1256)
那么是否可以更改范围键值?
So Is it possible to change the range Key value?
推荐答案
不,就像异常消息状态一样,您 无法更新属性 Date.该属性是键的一部分
.
No, like the exception message states, you Cannot update attribute Date. This attribute is part of the key
.
您还可以在 AttributeUpdates
文档:
You can also see this under the AttributeUpdates
documentation:
要修改的属性的名称,要对每个属性执行的操作,以及每个的新值.如果您要更新的属性是该表上任何索引的索引键属性,该属性type 必须与 AttributesDefinition 中定义的索引键类型匹配的表说明.您可以使用 UpdateItem 更新任何非键属性.
The names of attributes to be modified, the action to perform on each, and the new value for each. If you are updating an attribute that is an index key attribute for any indexes on that table, the attribute type must match the index key type defined in the AttributesDefinition of the table description. You can use UpdateItem to update any nonkey attributes.
文档声明您可以更新作为该表上任何索引的索引键属性的属性"的任何属性,这意味着当您更新投影到索引上的属性时,即使它是一部分在该索引键中,该索引也将被更新以反映原始项目.
The documentation states that you can update any attribute for "an attribute that is an index key attribute for any indexes on that table", which means that when you update an attribute that is projected onto an index, even it is is part of that indexes key, that index will also be updated to reflect the original item.
相关文章