add pgsql cursor util & silent stdout

This commit is contained in:
2020-06-06 14:08:22 -04:00
parent f92776e646
commit 7633c64057
3 changed files with 29 additions and 2 deletions

View File

@@ -129,3 +129,20 @@ def _deserialize(value, col_type):
if col_type == "blob":
return base64.b64decode(value)
return value
def pg_fetch_cursor_all(cur, name, batch_size=1000):
while True:
cur.execute("FETCH FORWARD %s FROM %s", (batch_size, name))
cnt = 0
for row in cur:
cnt += 1
yield row
if cnt != batch_size:
cur.execute("FETCH ALL FROM %s", (batch_size, name))
for row in cur:
yield row
break