feliperohde
feliperohde

Reputation: 43

DynamoDb: Perform updateExpression with string concatenation

Is there a way to concatenate string via UpdateExpressions? Let me explain better, for example, if a record has an id, thread and message, and for some reason, I intend to update one attribute with an information that already exists in the record, I could perform an expression like:

updateExpression = `SET #thread2 = #thread

it works, but unfortunately I couldn't do something beyond this, like a concatenation:

updateExpression = `SET #department = #thread + #id

or

updateExpression = `SET #department = #thread.#id

or

updateExpression = `SET #department = #thread#id

Some ideas? If not, I guess it could be very useful to avoid a GET before an UPDATE operation just to get an existent data and concatenate with some other stuff.

Upvotes: 4

Views: 4238

Answers (1)

notionquest
notionquest

Reputation: 39186

Unfortunately, there is no option to concatenate the String data directly in UpdateExpression (i.e. using + or any other operator or function).

The operator + can be used for Number data type to increment the value. However, it doesn't work for String data type.

As you mentioned, the only way to achieve this is get the item, concatenate the value and update the item.

Upvotes: 2

Related Questions