Skip to content

Commit

Permalink
Merge pull request #19 from jomonson/patch-1
Browse files Browse the repository at this point in the history
Treat empty tables the same as non-empty tables
  • Loading branch information
akaihola authored Apr 24, 2024
2 parents 230787a + 09d1782 commit 52580a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Removed

Fixed
-----

- Empty tables are now handled correctly.
- Very large tables are now sorted without crashing. This is done by merge sorting
in temporary files.

Expand All @@ -37,7 +37,7 @@ Added
Added
-----

Document ``pg_incremental_backup.py`` in the README file
- Document ``pg_incremental_backup.py`` in the README file


0.9_ / 2015-03-10
Expand Down
2 changes: 1 addition & 1 deletion pgtricks/pg_dump_splitsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pgtricks.mergesort import MergeSort

COPY_RE = re.compile(r'COPY .*? \(.*?\) FROM stdin;\n$')
COPY_RE = re.compile(r"COPY\s+\S+\s+(\(.*?\)\s+)?FROM\s+stdin;\n$")
KIBIBYTE, MEBIBYTE, GIBIBYTE = 2**10, 2**20, 2**30
MEMORY_UNITS = {"": 1, "k": KIBIBYTE, "m": MEBIBYTE, "g": GIBIBYTE}

Expand Down
29 changes: 28 additions & 1 deletion pgtricks/tests/test_pg_dump_splitsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,34 @@

import pytest

from pgtricks.pg_dump_splitsort import linecomp, memory_size, split_sql_file, try_float
from pgtricks.pg_dump_splitsort import (
COPY_RE,
linecomp,
memory_size,
split_sql_file,
try_float,
)


@pytest.mark.parametrize(
("test_input", "expected"),
[
("COPY table_name (column1, column2) FROM stdin;\n", True),
("COPY table_name (column1, column2) FROM stdin;\n", True),
("COPY table_name FROM stdin;\n", True),
("COPY table_name FROM stdin;\n", True),
("COPYtable_name FROM stdin;\n", False), # No space after COPY
("COPY table_name FROMstdin;\n", False), # No space before stdin
("COPY table_name FROM ;\n", False), # Missing stdin
("COPY table_name stdin;\n", False), # Missing FROM
("COPY FROM stdin;\n", False), # Missing table name
],
)
def test_sql_copy_regular_expression(test_input, expected):
"""Test that `COPY_RE` matches/doesn't match the expected strings."""
result = COPY_RE.match(test_input) is not None

assert result == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit 52580a1

Please sign in to comment.