[英]Updating an attribute in DynamoDB that starts with number in python
I have a nested object which may contain one attribute which starts with a numeric value.我有一个嵌套对象,它可能包含一个以数值开头的属性。
The update Expression is something like this:更新表达式是这样的:
set attr1.attr2.#numericAttr.attr3 = :value
the expressionAttribute dictionary is this: expressionAttribute 字典是这样的:
expressionAttrName:{#numericAttr: "29Wn5J8"}
My updateItem function of this type:我的这种类型的 updateItem 函数:
response = projectsTable.update_item(
Key={
"ABC": "value",
"DEF": "value2"
},
UpdateExpression=expression,
ExpressionAttributeNames=expressionAttrName,
ExpressionAttributeValues=attribute,
ReturnValues="UPDATED_NEW"
)
when I run this, I get ClientException stating:当我运行这个时,我得到 ClientException 说明:
('An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Syntax error; token: "29", near: ".29Wn5J8"',)
How to enable attributename to accept name starting with number?如何使属性名称接受以数字开头的名称?
As detailed in Expression Attribute Names in DynamoDB from the AWS Developer Documentation of DynamoDB:如DynamoDB的 AWS 开发人员文档中的 DynamoDB 中的表达式属性名称中所述:
Given the following table鉴于下表
{
"AttributeDefinitions": [
{
"AttributeName": "some_pk",
"AttributeType": "S"
}
],
"TableName": "test_table",
"KeySchema": [
{
"AttributeName": "some_pk",
"KeyType": "HASH"
}
],
"BillingMode": "PAY_PER_REQUEST"
}
With the following item与以下项目
{
"TableName": "test_table",
"Item": {
"some_pk": {
"S": "ITEM1"
},
"some_map": {
"M": {
"nested_map": {
"M": {
"1234": {
"M": {
"inner_value": {
"S": "1"
}
}
}
}
}
}
}
}
}
You can perform an update of some_map.nested_map.1234.inner_value
, like so:您可以执行some_map.nested_map.1234.inner_value
的更新,如下所示:
dynamo_client = boto3.resource('dynamodb')
table = dynamo_client.Table('test_table')
table.update_item(
Key={
'some_pk': 'ITEM1'
},
UpdateExpression='SET #attr1.#attr2.#attr3.#attr4 = :val1',
ExpressionAttributeNames={
'#attr1': "some_map",
'#attr2': "nested_map",
'#attr3': "1234",
'#attr4': "inner_value"
},
},
ExpressionAttributeValues={':val1': '2'},
ReturnValues='UPDATED_NEW'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.