|
17 | 17 | FractionalType, |
18 | 18 | Boolean, |
19 | 19 | Date, |
| 20 | + Time |
20 | 21 | ) |
21 | 22 | from data_diff.databases.base import BaseDialect, ThreadedDatabase, import_helper, ConnectError |
22 | 23 | from data_diff.databases.base import ( |
@@ -57,6 +58,8 @@ class PostgresqlDialect(BaseDialect): |
57 | 58 | "timestamp without time zone": Timestamp, |
58 | 59 | "timestamp": Timestamp, |
59 | 60 | "date": Date, |
| 61 | + "time with time zone": Time, |
| 62 | + "time without time zone": Time, |
60 | 63 | # Numbers |
61 | 64 | "double precision": Float, |
62 | 65 | "real": Float, |
@@ -111,6 +114,23 @@ def normalize_timestamp(self, value: str, coltype: TemporalType) -> str: |
111 | 114 | def _add_padding(coltype: TemporalType, timestamp6: str): |
112 | 115 | return f"RPAD(LEFT({timestamp6}, {TIMESTAMP_PRECISION_POS+coltype.precision}), {TIMESTAMP_PRECISION_POS+6}, '0')" |
113 | 116 |
|
| 117 | + try: |
| 118 | + is_date = coltype.is_date |
| 119 | + is_time = coltype.is_time |
| 120 | + except: |
| 121 | + is_date = False |
| 122 | + is_time = False |
| 123 | + |
| 124 | + if isinstance(coltype, Date) or is_date: |
| 125 | + return f"cast({value} as varchar)" |
| 126 | + |
| 127 | + if isinstance(coltype, Time) or is_time: |
| 128 | + seconds = f"EXTRACT( epoch from {value})" |
| 129 | + rounded = f"ROUND({seconds}, {coltype.precision})" |
| 130 | + time_value = f"CAST('00:00:00' as time) + make_interval(0, 0, 0, 0, 0, 0, {rounded})" # 6th arg = seconds |
| 131 | + converted = f"to_char({time_value}, 'hh24:mi:ss.ff6')" |
| 132 | + return converted |
| 133 | + |
114 | 134 | if coltype.rounds: |
115 | 135 | # NULL value expected to return NULL after normalization |
116 | 136 | null_case_begin = f"CASE WHEN {value} IS NULL THEN NULL ELSE " |
|
0 commit comments