Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 7831bc7

Browse files
committed
Fixes for postgresql
1 parent 7d94282 commit 7831bc7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

data_diff/databases/postgresql.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .base import ThreadedDatabase, import_helper, ConnectError
33
from .base import MD5_HEXDIGITS, CHECKSUM_HEXDIGITS, _CHECKSUM_BITSIZE, TIMESTAMP_PRECISION_POS
44

5+
SESSION_TIME_ZONE = None # Changed by the tests
56

67
@import_helper("postgresql")
78
def import_postgresql():
@@ -47,13 +48,17 @@ def _convert_db_precision_to_digits(self, p: int) -> int:
4748
return super()._convert_db_precision_to_digits(p) - 2
4849

4950
def create_connection(self):
51+
if not self._args:
52+
self._args['host'] = None # psycopg2 requires 1+ arguments
53+
5054
pg = import_postgresql()
5155
try:
5256
c = pg.connect(**self._args)
53-
# c.cursor().execute("SET TIME ZONE 'UTC'")
57+
if SESSION_TIME_ZONE:
58+
c.cursor().execute(f"SET TIME ZONE '{SESSION_TIME_ZONE}'")
5459
return c
5560
except pg.OperationalError as e:
56-
raise ConnectError(*e._args) from e
61+
raise ConnectError(*e.args) from e
5762

5863
def quote(self, s: str):
5964
return f'"{s}"'

tests/test_database_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from parameterized import parameterized
1313

1414
from data_diff import databases as db
15+
import data_diff.databases.postgresql as postgresql
1516
from data_diff.utils import number_to_human
1617
from data_diff.diff_tables import TableDiffer, TableSegment, DEFAULT_BISECTION_THRESHOLD
1718
from .common import CONN_STRINGS, N_SAMPLES, N_THREADS, BENCHMARK, GIT_REVISION, random_table_suffix
@@ -20,6 +21,7 @@
2021
CONNS = {k: db.connect_to_uri(v, N_THREADS) for k, v in CONN_STRINGS.items()}
2122

2223
CONNS[db.MySQL].query("SET @@session.time_zone='+00:00'", None)
24+
postgresql.SESSION_TIME_ZONE = 'UTC'
2325

2426

2527
class PaginatedTable:

0 commit comments

Comments
 (0)