gpt4 book ai didi

java - 如何使用 dynamodb sdk 将字符串附加到列表? ( java )

转载 作者:行者123 更新时间:2023-11-30 07:17:23 25 4
gpt4 key购买 nike

非常简单的问题,但由于某种原因,任何地方都没有正确的文档。这是我正在实现的:

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

我本质上只是希望能够将字符串附加到数据库中项目的列表中。我已经尝试了文档建议的所有内容(所以基本上是 1 个示例)和许多线程,但没有任何效果。

我当前收到的错误是:

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)

最佳答案

使用以下 UpdateExpression:

String.format("SET %s = list_append(%s, :append_value)", LIST_NAME, LIST_NAME)

关于java - 如何使用 dynamodb sdk 将字符串附加到列表? ( java ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38134454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com