1

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)"

2
  • according to the docs, "If you need to compare an attribute with a value, define an expression attribute value as a placeholder". In multiple places in the DDB documentation, there are notes saying "an expression attribute value must be defined for ___" such as the attribute_type function in ConditionExpression Functions. Commented Nov 26, 2021 at 19:18
  • Why do you think you need to do this without using ExpressionAttributeValues? Commented Nov 26, 2021 at 19:34

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.