![](/img/trans.png)
[英]Getting Error While Inserting JSON data to DynamoDB using Python
[英]Getting errors while trying to update column in DynamoDb using python client
我有一個dynamoDB表,其鍵名為id和一個名為state的String字段。 我只想使用update_item DynamoDb Python客戶端更新狀態值。
DDB_CLIENT.update_item(
Key={
'id' : {'S': id}
},
TableName='TrackingState',
UpdateExpression="set state = :r",
ExpressionAttributeValues={
':r': '"state": {"S": "IN_PROGRESS"}'
}
)
我收到一個錯誤: 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
如果我嘗試
':r' : {"S": "QUEUED"}
Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: state
什么是更新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"}
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.