是否可以在update_item中组合if_not_exists和list_append [英] Is it possible to combine if_not_exists and list_append in update_item
问题描述
我正在尝试在boto3中为DynamoDB使用 update_item
功能。
我正在努力更新商品清单。如果列表尚不存在,我想创建一个新列表,否则添加到现有列表中。
使用 SET形式的
返回错误如果列表尚不存在,则提供的表达式指向该项目中不存在的属性。 b $ b UpdateExpression
SET my_list = list_append(my_list,:my_value)
任何想法我将如何修改我的 UpdateExpression
?
感谢&最好的问候,
Fabian
您可以使用 list_append(if_not_exists())
构造。
UpdateExpression:
'SET my_list2 = list_append(if_not_exists(my_list2,:empty_list),:my_value)'
ExpressionAttributeValues:
{:my_value:[{ S: test}],:empty_list:[]}
I'm trying to use the update_item
functionality for DynamoDB in boto3.
I'm struggling right now to update lists for items. I would like to create a new list if the list does not exist yet and otherwise append to the existing list.
Using an UpdateExpression
of the form SET my_list = list_append(my_list, :my_value)
returns an error "The provided expression refers to an attribute that does not exist in the item" if the list does not exist yet.
Any idea how I would have to modify my UpdateExpression
?
Thanks & best regards, Fabian
You can use list_append(if_not_exists())
construction.
UpdateExpression:
'SET my_list2 = list_append(if_not_exists(my_list2, :empty_list), :my_value)'
ExpressionAttributeValues:
{ ":my_value":[{"S":"test"}], ":empty_list":[] }
这篇关于是否可以在update_item中组合if_not_exists和list_append的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!