Closed vladiscripts closed 3 years ago
this is an unfortunate outcome of having a delightfully simple API
to solve this, you can iterate over the rows you wish to change and then upsert them
rows = t.find(value=1)
# python < 3.9
updated = ({**row, **dict(value=2)} for row in rows)
# python > 3.9
updated = (row | dict(value=2) for row in rows)
t.upsert_many(updated, ['id'])
if you're feeling brave you can try doing it all in one line
t.upsert(({**row, **dict(value=2)} for row in r.find(value=1)), ['id'])
thanks for the advice, @medecau.
Is it possible to make
update
with the same parameter? I want to find all the values "value = 1" in the table and replace them with "value = 2". SQL analog:UPDATE table SET value=2 WHERE value=1
. The providedupdate
function works only as a unique search filter, for example,update({'value': 1}, keys = ['value'])
does not allow changing the value to 2.