# Multiupdate by query

**URL:** <https://discuss.aerospike.com/t/multiupdate-by-query/8040>\
**Category:** General Discussion\
**Tags:** query\
**Created:** [November 30, 2020, 10:32am UTC](https://discuss.aerospike.com/t/multiupdate-by-query/8040 "2020-11-30T10:32:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itrnka](https://avatars.discourse-cdn.com/v4/letter/i/f4b2a3/32.png) [@itrnka](https://discuss.aerospike.com/u/itrnka)\
**Post date:** [November 30, 2020, 10:32am UTC](https://discuss.aerospike.com/t/multiupdate-by-query/8040/1 "2020-11-30T10:32:30Z")

</div>

Is there any alternative in Aerospike to this SQL expression? UPDATE products SET price = price \* {$myVariable};

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [December 10, 2020, 4:18am UTC](https://discuss.aerospike.com/t/multiupdate-by-query/8040/2 "2020-12-10T04:18:50Z")

</div>

So currently you would do this with a record UDF that you apply to all the records in the namespace (or set) _products_.

```nohighlight
function update_multiply(rec, bin_name, multiplier)
    if aerospike:exists(rec) then
        local value = rec[bin_name]
        rec[bin_name] = value * multiplier
        aerospike:update(rec)
    end
end

```

Now to run the example, I’ll use the `aql` command-line tool. In the real world, you’d call it from a language client, once you’ve debugged your Lua code.

```sql
KEY_SEND = true

aql> SELECT * FROM test.products
+------------+---+
| PK | i |
+------------+---+
| "here" | 2 |
| "there" | 3 |
| "anywhere" | 4 |
+------------+---+
3 rows in set (0.187 secs)

OK

aql> REGISTER MODULE 'update.lua'
OK, 1 module added.

aql> EXECUTE update.update_multiply("i", 2) ON test.products
OK, Scan job (9319251124864029115) created.

aql> SELECT * FROM test.products
+------------+---+
| PK | i |
+------------+---+
| "here" | 4 |
| "there" | 6 |
| "anywhere" | 8 |
+------------+---+
3 rows in set (0.175 secs)

```

In a near future release of Aerospike Database you’ll be able to do this with a Write [Expression](https://www.aerospike.com/docs/guide/expressions/) instead of a UDF. At the moment Expressions are just used as a filter, allowing you to put a condition on whether a record operation, batch-read, scan, query or UDF call happens. Their use will be expanded.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [December 10, 2021, 4:18am UTC](https://discuss.aerospike.com/t/multiupdate-by-query/8040/3 "2021-12-10T04:18:51Z")

</div>

Closed on December 10, 2021, 4:18am UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
