Skip to content

Commit

Permalink
Write all COPY data in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Kaihola authored and akaihola committed Apr 19, 2024
1 parent 1775695 commit 0643ebd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pgtricks/pg_dump_splitsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import re
import sys
from typing import IO, List, Match, Optional, Pattern, Tuple, Union, cast
from typing import IO, List, Match, Optional, Pattern, Tuple, Union, cast, Iterable

from pgtricks.mergesort import MergeSort

Expand Down Expand Up @@ -65,10 +65,10 @@ def flush() -> None:
output.writelines(buf)
buf[:] = []

def writeline(line_: str) -> None:
def writelines(lines: Iterable[str]) -> None:
if buf:
flush()
output.write(line_)
output.writelines(lines)

def new_output(filename: str) -> IO[str]:
if output:
Expand All @@ -85,7 +85,7 @@ def new_output(filename: str) -> IO[str]:
if line in ('\n', '--\n'):
buf.append(line)
elif line.startswith('SET search_path = '):
writeline(line)
writelines([line])
else:
if matcher.match(DATA_COMMENT_RE, line):
counter += 1
Expand All @@ -103,12 +103,11 @@ def new_output(filename: str) -> IO[str]:
elif 1 <= counter < 9999:
counter = 9999
output = new_output('%04d_epilogue.sql' % counter)
writeline(line)
writelines([line])
else:
if line == "\\.\n":
for copy_line in copy_lines:
writeline(copy_line)
writeline(line)
writelines(copy_lines)
writelines(line)
copy_lines = None
else:
copy_lines.append(line)
Expand Down

0 comments on commit 0643ebd

Please sign in to comment.