Dynamo DB : UpdateItemSpec : Multiple Update Expression - Not Working

泄露秘密 提交于 2019-12-24 08:57:55

问题


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:


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


来源:https://stackoverflow.com/questions/50664248/dynamo-db-updateitemspec-multiple-update-expression-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!