You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A recurrent challenge in writing upgrade scripts is that of updating values in a
table based on some form of already available mapping from the id (or another
identifier) to the new value, this is often addressed with an iterative solution
in the form:
```python
for key, value in mapping.items():
cr.execute(
"""
UPDATE table
SET col = %s
WHERE key_col = %s
""",
[value, key],
)
```
or in a more efficient (only issuing a single query) but hacky way:
```python
cr.execute(
"""
UPDATE table
SET col = (%s::jsonb)->>(key_col::text)
WHERE key_col = ANY(%s)
""",
[json.dumps(mapping), list(mapping)],
)
```
With the former being ineffective for big mappings and the latter often
requiring some comments at review time to get it right.
This commit introduces a util meant to make it easier to efficiently perform
such updates.
closes#297
Signed-off-by: Christophe Simonis (chs) <[email protected]>
0 commit comments