Reputation: 11
I need to make a comparison in a ConditionExpression of the form '(#i.body_uncommon = 1)' without using ExpressionAttributeValues, what should the syntax be? I looked at all the documentation and did not find an example
For example so:
response = table.update_item(
Key={
'ID': "jr_test"
}
, ConditionExpression='(#i.body_uncommon = 1)'
, UpdateExpression=final_str
, ExpressionAttributeNames={
"#i": "items"
}
)
But this code throws a syntax error in the place: token: "1", near: "= 1)"
Upvotes: 1
Views: 1394
Reputation: 2042
DynamoDB does not accept literal values within expressions. Expressions must use placeholders in conjunction with the ExpressionAttributeValues
parameter to specify literal values.
This API essentially enforces best practices to prevent injection attacks.
From Expressions:
If you need to compare an attribute with a value, define an expression attribute value as a placeholder.
Even functions that accept specific values as arguments, such as the attribute_type
function for a ConditionExpression, specify that the values must be defined using expression attribute values.
You must use an expression attribute value for the
type
parameter.
Upvotes: 2