无效的UpdateExpression:运算符或函数的操作数类型错误;运算符:ADD,操作数类型:LIST [英] Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: LIST

查看:217
本文介绍了无效的UpdateExpression:运算符或函数的操作数类型错误;运算符:ADD,操作数类型:LIST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在UpdateExpression中使用ADD将电子邮件字符串添加到字符串集(代码如下),但遇到此异常:无效的UpdateExpression:运算符或函数的操作数类型错误;

I tried to use ADD in UpdateExpression to add an email string into a string set , code as below , but hit this exception : Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: LIST.

我认为关键是我需要一种将类型更改为字符串集的方法,但不确定是什么

I think the point is that I need a way to change the type into "string set" , but not sure what is the semantic to achieve that.

        response = wishesTable.update_item(
            Key={
                'title': wishTitle,
                'userMail': wishUsermail
            },
            UpdateExpression='ADD whoLikeList :my_value',
            ExpressionAttributeValues={
                ":my_value": [userEmail]
            },
            ReturnValues="UPDATED_NEW"
        )


推荐答案

通过引用TypeSerializer类( http ://boto3.readthedocs.io/zh-CN/latest/_modules/boto3/dynamodb/types.html

By referring to TypeSerializer class ( http://boto3.readthedocs.io/en/latest/_modules/boto3/dynamodb/types.html )

将代码更改为

        response = wishesTable.update_item(
            Key={
                'title': wishTitle,
                'userMail': wishUsermail
            },
            UpdateExpression='ADD whoLikeList :my_value',
            ExpressionAttributeValues={
                ":my_value": set([userEmail])
            },
            ReturnValues="UPDATED_NEW"
        )

这篇关于无效的UpdateExpression:运算符或函数的操作数类型错误;运算符:ADD,操作数类型:LIST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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