How to separate multiple clauses in a DynamoDB Update Expression

Viewed 3754

Per the AWS Docs:

An update expression consists of one or more clauses. Each clause begins with a SET, REMOVE, ADD or DELETE keyword. You can include any of these clauses in an update expression, in any order. However, each action keyword can appear only once.

I'm having trouble getting the syntax right for SET and REMOVE in one update_expression:

params = {
           key: {
             'id' => { s: '123'  }
           },
           table_name: 'customers'
           expression_attribute_names: {
             '#ADR' => 'address'
             '#ON' => 'order_num'
           },
           expression_attribute_values: {
             ':a' => { s: '123 Main St' }
           },
           update_expression: 'REMOVE #ON, SET #ADR = :a',
         }
  dynamodb = Aws::DynamoDB::Client.new(region: 'us-east-1',       
                                       simple_attributes: false)
  dynamodb.update_item(params)

I also tried the following:

update_expression: 'SET #ADR = :a, REMOVE #ON' => Invalid UpdateExpression: Syntax error; token: "REMOVE", near: ", REMOVE #ON" (Aws::DynamoDB::Errors::ValidationException)

update_expression: ['SET #ADR = :a', 'REMOVE #ON'] => expected params[:update_expression] to be a String, got value ['SET #ADR = :a', 'REMOVE #ON'] (class: Array) instead. (ArgumentError)

Can anyone point me to the right docs?

1 Answers
Related