我正在尝试使用多个更新表达式添加/更新表中的记录(行) -
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);
但是我收到了错误 -
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)
因此我有以下查询 -
答案 0 :(得分:0)
我找到了第一个和第二个问题的答案。
不允许多个UpdateExpressions,但在同一个updateExpression中将每个操作与(,)分开。
.withUpdateExpression("set #vsg_tid = :vsg_tidValue , #ttl = if_not_exists(#ttl,:ttlValue)")