pgroonga: Fix do_batch_update logic for all postgres versions.

Apparently, the fix in 430ed061c1
requires a sufficiently modern postgres version not available in
Xenial.

Fixes #12382.

Patch by Sutou Kouhei.
This commit is contained in:
Tim Abbott 2019-05-29 14:57:49 -07:00
parent 857c16d52d
commit 7134a12231
1 changed files with 4 additions and 2 deletions

View File

@ -36,11 +36,13 @@ def do_batch_update(cursor: CursorObj,
batch_size: int=10000,
sleep: float=0.1,
escape: bool=True) -> None: # nocoverage
# The string substitution below is complicated by our need to
# support multiple postgres versions.
stmt = '''
UPDATE %s
SET (%s) = ROW(%s)
SET %s
WHERE id >= %%s AND id < %%s
''' % (table, ', '.join(cols), ', '.join(['%s'] * len(cols)))
''' % (table, ', '.join(['%s = %%s' % (col) for col in cols]))
cursor.execute("SELECT MIN(id), MAX(id) FROM %s" % (table,))
(min_id, max_id) = cursor.fetchall()[0]