Dynamo DB : UpdateItemSpec : Multiple Update Expre

2019-08-08 14:38发布

I am trying to add/update a record(row) in the table with multiple update expression as -

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

But I am getting an error -

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)

Hence I have following queries -

  1. Does UpdateItemSpec does not allow multiple Update Expressions?
  2. Is there a way to provide multiple SET operations?
  3. If there is a way, will the operations be atomic in nature?

1条回答
甜甜的少女心
2楼-- · 2019-08-08 15:12

I found the answer to the first and second question.

Multiple UpdateExpressions are not allowed but separating each operation with (,) in the same updateExpression works.

.withUpdateExpression("set #vsg_tid = :vsg_tidValue , #ttl = if_not_exists(#ttl,:ttlValue)")
查看更多
登录 后发表回答