Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I need to update the timestamp attribute in my dynamodb table using boto3 but the attribute name "timestamp" is a reserved word so it's throwing an error on the SET command.

table.update_item(

    Key={

        'id': item_id

    },

    UpdateExpression='SET timestamp = :val1', # this is the line giving the problem

    ExpressionAttributeValues={

        ":val1": new_timestamp

    }

)

"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: timestamp",

1 Answer

0 votes
by (44.4k points)

There is a workaround using expression attribute names. 

table.update_item(

  Key={

    'id': item_id

  },

  UpdateExpression='SET #ts = :val1',

  ExpressionAttributeValues={

    ":val1": new_timestamp

  },

  ExpressionAttributeNames={

    "#ts": "timestamp"

  }

)

Check out this doc for more info Expression Attribute Names

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...