Vadim  Novitskiy
Vadim Novitskiy

Reputation: 179

Windows Azure Table Storage int field increment

I thinking about great improvement of Azure Table Storage. Is it possible to submit query to Table Storage with specific operation such as "increment entity field [name] by [value] where [PartitionKey=somestingPK] and [RowKey=somethingRK]"?

@smarx is this feature will be available?

Upvotes: 5

Views: 4068

Answers (3)

makerofthings7
makerofthings7

Reputation: 61483

You can accomplish this with either Table or Page storage with ETAG tracking enabled. I use this technique to create an Identity value for each entry in Azure Table. The idea goes like this:

  • Read the value from the Page Blob, leave ETAG tracking enabled

  • Increment the retrieved value

  • POST the retrieved value, and if there is an ETAG conflict, retry the whole operation again fresh. Perhaps use an exponential backoff algorithm here to prevent overloading the target container or partition.

Upvotes: 5

dunnry
dunnry

Reputation: 6868

Yes, this is possible - but perhaps not exactly the way you are thinking. You are looking for the MERGE operation. To use it, you must know the entity (i.e the partition key and rowkey of the entity) you are targeting. You do not have to retrieve the entity to update it, but you must specifically address each entity either per REST call or using the batch capabilities (which has some restrictions).

Upvotes: 1

Thanos Makris
Thanos Makris

Reputation: 3115

This is similar to UPDATE query of MySQL and currently is not possible to perform in Azure Table Storage. Not sure if this is possible to achieve in such a database type, since you have first to get the whole entity, update the fields you want, and store back to the database.

Upvotes: 0

Related Questions