Question:
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
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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:
1 2 3 4 |
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?
Answer:
I was making it too complicated.
This is the answer:
1 2 |
update_expression: 'SET #ADR = :a REMOVE #ON' |
No delimiter character needed besides the Clause keyword.