use*_*726 2 java amazon-dynamodb aws-sdk
我正在尝试使用多个更新表达式添加/更新表中的记录(行) -
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("phoneNumber",phoneNumber)
.withReturnValues(ReturnValue.ALL_NEW)
.withUpdateExpression("set #tid = :tidValue")
.withUpdateExpression("set #ttl = if_not_exists(#ttl,:ttlValue)")
.withNameMap(new NameMap().with("#ttl","ttl").with("#tid", "tid"))
.withValueMap(new ValueMap().with(":ttlValue",ttl).with(":tidValue", tid));
table.updateItem(updateItemSpec);
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误 -
Exception in thread "main" com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: Value provided in ExpressionAttributeNames unused in expressions: keys: {#tid} (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 6d8e2119-cb73-43f2-a3ab-3868ab822630)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1630)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1302)
Run Code Online (Sandbox Code Playgroud)
因此我有以下疑问 -
我找到了第一个问题和第二个问题的答案。
不允许使用多个 UpdateExpression,但可以在同一 updateExpression 中使用 (,) 分隔每个操作。
.withUpdateExpression("set #vsg_tid = :vsg_tidValue , #ttl = if_not_exists(#ttl,:ttlValue)")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4799 次 |
| 最近记录: |