use*_*342 3 python-3.x amazon-dynamodb aws-sdk boto3
我有一个 dynamoDB 表,其键名为 id 和一个名为 state 的字符串字段。我只想使用 update_item DynamoDb Python 客户端更新状态值。
DDB_CLIENT.update_item(
Key={
'id' : {'S': id}
},
TableName='TrackingState',
UpdateExpression="set state = :r",
ExpressionAttributeValues={
':r': '"state": {"S": "IN_PROGRESS"}'
}
)
Run Code Online (Sandbox Code Playgroud)
我收到错误:Invalid type for parameter ExpressionAttributeValues type: <class 'str'>, valid types: <class 'dict'>
如果我尝试将 expressionAttributeValues 设为:
':r' : {"state": {"S": "IN_PROGRESS"}} I get the error: Unknown parameter in ExpressionAttributeValues.:r: "state", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
Run Code Online (Sandbox Code Playgroud)
如果我尝试
':r' : {"S": "QUEUED"}
Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: state
Run Code Online (Sandbox Code Playgroud)
更新 DynamoDb 表中条目的正确方法是什么
如果我尝试
':r' : {"S": "QUEUED"} 无效的 UpdateExpression:属性名称是保留关键字;保留关键字:状态
没错,state关键字不能在表达式中使用,所以ExpressionAttributeNames字典允许使用它。
DDB_CLIENT.update_item(
Key={
'id' : {'S': id}
},
TableName='TrackingState',
UpdateExpression="set #s = :r",
ExpressionAttributeNames={
'#s': "state"
},
ExpressionAttributeValues={
':r': {"S": "QUEUED"}
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2178 次 |
| 最近记录: |