是否可以在DynamoDB表中更改Range键的值? [英] Is It possible to change value of Range key in DynamoDB Table?

查看:69
本文介绍了是否可以在DynamoDB表中更改Range键的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能是一个非常愚蠢的问题,但是我是DynamoDB的新手。

I know it may be a very silly question, but I am new to DynamoDB.

我的疑问是是否有可能更新Range键的值DynamoDB。

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"
}

在下面运行此代码。我可以更改 Name 属性,即GSI。

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);

我遇到了一些错误,因为

I am getting some error as

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?

推荐答案

否,与异常消息状态一样,您无法更新属性日期。此属性是键的一部分。。

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:


要修改的属性名称,每个属性执行的操作,
以及每个属性的新值。如果要更新的属性
是该表上任何索引的索引键属性,则属性
类型必须与表描述的AttributesDefinition
中定义的索引键类型匹配。 您可以使用UpdateItem更新任何非键
属性。

文档指出您可以更新该表上所有索引的索引键属性的属性的任何属性,这意味着当更新投影到索引的属性时,即使它是该索引键的一部分,该索引也将进行更新以反映原始项目。

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.

这篇关于是否可以在DynamoDB表中更改Range键的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆