Reputation: 813
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 -
Upvotes: 2
Views: 4993
Reputation: 813
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)")
Upvotes: 5