[英]adding new column in dynamo DB using boto3 resource with update_item
I need to update a row in Dynomodb while doing so need to include a new column which is already not there.我需要更新 Dynomodb 中的一行,同时需要包含一个已经不存在的新列。
resp = table.update_item(
Key={
'Pkey': 'key1',
'Skey': 'skwy2'
},
UpdateExpression='ADD dateModified = :input2, SET IsActive = :input1',
ExpressionAttributeValues={
':input1': False,
':input2' : datetime.datetime.now(timezone.utc)
},
ReturnValues="UPDATED_NEW"
)
now I need to update IsActive field to false and insert new dateModified value to that .现在我需要将 IsActive 字段更新为 false 并在其中插入新的 dateModified 值。
getting error as Invalid UpdateExpression: Syntax error;获取错误为无效 UpdateExpression:语法错误; token: "=", near: "dateModified = :input2"
令牌:“=”,附近:“dateModified = :input2”
you can see in https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD that for the ADD
operation you don't use =
您可以在https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD中看到,对于您不使用的
ADD
操作=
so the correct expression should be ADD dateModified :input2 SET IsActive = :input1
所以正确的表达式应该是
ADD dateModified :input2 SET IsActive = :input1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.