非常简单的问题,但由于某种原因,任何地方都没有正确的文档。以下是我正在实施的内容:
public static AttributeValue pushMessage(String ID,String message)
{
Map<String, AttributeValue> itemKey = mapKey(KEY, new AttributeValue(ID));
UpdateItemRequest request = new UpdateItemRequest();
request.setTableName(TABLE_NAME);
request.setKey(itemKey);
/*I don't know what to put for the update expression*/
//request.setUpdateExpression("ADD #"+LIST_NAME+" :append_value)");
request.setUpdateExpression("list_append("+LIST_NAME+", :append_value)");
request.setExpressionAttributeValues(Collections.singletonMap(":append_value", new AttributeValue(message)));
UpdateItemResult result = dynamoDB.updateItem(request);
}
我基本上只是希望能够将字符串附加到我的数据库中的项目列表中。我已经尝试了文档提出的所有内容(基本上只有一个示例)和众多线程,但没有任何作用。
我目前得到的错误是:
Exception in thread "main" com.amazonaws.AmazonServiceException: Invalid UpdateExpression: Syntax error; token: "list_append", near: "list_append(" (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException;
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1372)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:919)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:697)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:449)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:411)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:360)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2048)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2018)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1845)
at DBConnector.pushMessage(DBConnector.java:486)
at DBConnector.main(DBConnector.java:506)
答案 0 :(得分:1)
使用以下UpdateExpression:
String.format("SET %s = list_append(%s, :append_value)", LIST_NAME, LIST_NAME)