Dynamo DB:UpdateItemSpec:多个更新表达式-不起作用 [英] Dynamo DB : UpdateItemSpec : Multiple Update Expression - Not Working
本文介绍了Dynamo DB:UpdateItemSpec:多个更新表达式-不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下多个更新表达式在表中添加/更新记录(行)-
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);
但是我遇到了错误-
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)
因此我有以下查询-
- UpdateItemSpec不允许多个更新表达式吗?
- 是否可以提供多个更新表达式? SET操作?
- 如果有办法,这些操作本质上是原子的吗?
推荐答案
我找到了第一个和山高的答案第二个问题。
I found the answer to the first and second question.
不允许使用多个UpdateExpressions,但是在同一updateExpression作品中,每个操作都用(,)分隔。
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)")
这篇关于Dynamo DB:UpdateItemSpec:多个更新表达式-不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文