运算符或函数的操作数类型不正确;运算符:添加,操作数类型:字符串,排版:允许\u添加\u操作数

2024-10-01 17:33:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更新DynamoDB中的一行并添加新列

resp = table.update_item(
            Key={
                'Pkey': 'key1',
                'Skey': 'skwy2'
            },
            UpdateExpression='ADD dateModified :input2, SET IsActive = :input1',
            ExpressionAttributeValues={
                ':input1': False,
                ':input2' : 'Test'
            },
            ReturnValues="UPDATED_NEW"
        )

在input2中获取错误, 我甚至还试过

':input2': {'S' : "Test"}

那不行

为什么我要面对这个问题


Tags: keytestaddtableupdateitemdynamodbresp
1条回答
网友
1楼 · 发布于 2024-10-01 17:33:23

您可以查看文档https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD-ADD处理数字和集合

The ADD action supports only number and set data types.

还有一个注意事项:

In general, we recommend using SET rather than ADD.

因为您想要添加新值,SET完全能够做到这一点。从https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET

Use the SET action in an update expression to add one or more attributes to an item. If any of these attributes already exists, they are overwritten by the new values.

因此,您可以跳过添加操作,只需使用SET

但是,根据python库的不同,您可能需要将值包装为{"BOOL":false}{"S":"Test"}

相关问题 更多 >

    热门问题