Skip to content

Commit 66fbad6

Browse files
cpcloudgforsyth
authored andcommitted
fix(oracle): render dates and timestamps correctly
1 parent aca30e1 commit 66fbad6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

ibis/backends/oracle/registry.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,29 @@ def _corr(t, op):
4343

4444

4545
def _literal(t, op):
46-
if (
46+
dtype = op.dtype
47+
value = op.value
48+
49+
if value is None:
50+
return sa.null()
51+
elif (
4752
# handle UUIDs in sqlalchemy < 2
48-
vparse(sa.__version__) < vparse("2")
49-
and (dtype := op.dtype).is_uuid()
50-
and (value := op.value) is not None
53+
vparse(sa.__version__) < vparse("2") and dtype.is_uuid()
5154
):
5255
return sa.literal(str(value), type_=t.get_sqla_type(dtype))
56+
elif dtype.is_timestamp():
57+
if dtype.timezone is not None:
58+
return sa.func.to_utc_timestamp_tz(value.isoformat(timespec="microseconds"))
59+
return sa.func.to_timestamp(
60+
# comma for sep here because T is a special character in Oracle
61+
# the FX prefix means "requires an exact match"
62+
value.isoformat(sep=",", timespec="microseconds"),
63+
"FXYYYY-MM-DD,HH24:MI:SS.FF6",
64+
)
65+
elif dtype.is_date():
66+
return sa.func.to_date(value.isoformat(), "FXYYYY-MM-DD")
67+
elif dtype.is_time():
68+
raise NotImplementedError("Time values are not supported in Oracle")
5369
return _alchemy_literal(t, op)
5470

5571

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT
2+
TO_DATE('2023-04-07', 'YYYY-MM-DD') AS "datetime.date(2023, 4, 7)"
3+
FROM DUAL
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT
2+
TO_TIMESTAMP('2023-04-07T04:05:06.230136', 'YYYY-MM-DDTHH24:MI:SS.FF') AS "datetime.datetime(2023, 4, 7, 4, 5, 6, 230136)"
3+
FROM DUAL

0 commit comments

Comments
 (0)