Dynamodb使用python boto3更新项目表达式 [英] Dynamodb Update Item Expression with python boto3

查看:154
本文介绍了Dynamodb使用python boto3更新项目表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串字段 title。我正在尝试使用更新表达式来更新它,

I have a string field, "title". I am trying to update it with the update expression with

persontable.update_item(Key={'person_id':person_id}, UpdateExpression="SET title = UPDATED")

我得到

An error occurred (ValidationException) when calling the UpdateItem operation: The provided expression refers to an attribute that does not exist in the item

我可以在AWS控制台中看到该人的属性 title。

I can see the attribute "title" for that person in the AWS console. What gives?

推荐答案

不要将值直接插入表达式中。而是使用 ExpressionAttributeValues -请参见 boto3指南

Don't plug the value into the expression directly. Rather use ExpressionAttributeValues -- see boto3 guide

persontable.update_item(Key={'person_id':person_id},
                        UpdateExpression="SET title = :updated",                   
                        ExpressionAttributeValues={':updated': 'UPDATED'})

这篇关于Dynamodb使用python boto3更新项目表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆