Skip to content

Commit

Permalink
fix(oracle): render dates and timestamps correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Dec 12, 2023
1 parent aca30e1 commit 66fbad6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ibis/backends/oracle/registry.py
Expand Up @@ -43,13 +43,29 @@ def _corr(t, op):


def _literal(t, op):
if (
dtype = op.dtype
value = op.value

if value is None:
return sa.null()
elif (
# handle UUIDs in sqlalchemy < 2
vparse(sa.__version__) < vparse("2")
and (dtype := op.dtype).is_uuid()
and (value := op.value) is not None
vparse(sa.__version__) < vparse("2") and dtype.is_uuid()
):
return sa.literal(str(value), type_=t.get_sqla_type(dtype))
elif dtype.is_timestamp():
if dtype.timezone is not None:
return sa.func.to_utc_timestamp_tz(value.isoformat(timespec="microseconds"))
return sa.func.to_timestamp(
# comma for sep here because T is a special character in Oracle
# the FX prefix means "requires an exact match"
value.isoformat(sep=",", timespec="microseconds"),
"FXYYYY-MM-DD,HH24:MI:SS.FF6",
)
elif dtype.is_date():
return sa.func.to_date(value.isoformat(), "FXYYYY-MM-DD")
elif dtype.is_time():
raise NotImplementedError("Time values are not supported in Oracle")
return _alchemy_literal(t, op)


Expand Down
@@ -0,0 +1,3 @@
SELECT
TO_DATE('2023-04-07', 'YYYY-MM-DD') AS "datetime.date(2023, 4, 7)"
FROM DUAL
@@ -0,0 +1,3 @@
SELECT
TO_TIMESTAMP('2023-04-07T04:05:06.230136', 'YYYY-MM-DDTHH24:MI:SS.FF') AS "datetime.datetime(2023, 4, 7, 4, 5, 6, 230136)"
FROM DUAL

0 comments on commit 66fbad6

Please sign in to comment.