Skip to content

Commit

Permalink
fix(duckdb): use functions for temporal literals
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Dec 12, 2023
1 parent 0e896c6 commit b1407f8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ibis/backends/duckdb/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,14 @@ def _literal(t, op):
return sa.func.map(
sa.func.list_value(*value.keys()), sa.func.list_value(*value.values())
)
elif dtype.is_timestamp():
return sa.cast(value.isoformat(), t.get_sqla_type(dtype))
elif dtype.is_date():
return sa.cast(sa.literal(str(value)), sqla_type)
return sa.func.make_date(value.year, value.month, value.day)
elif dtype.is_time():
return sa.func.make_time(
value.hour, value.minute, value.second + value.microsecond / 1e6
)
else:
return sa.cast(sa.literal(value), sqla_type)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
MAKE_DATE(2023, 4, 7) AS "datetime.date(2023, 4, 7)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
MAKE_TIME(4, 5, 6) AS "datetime.time(4, 5, 6, 230136)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
MAKE_TIMESTAMP(1680854706230136) AS "datetime.datetime(2023, 4, 7, 4, 5, 6, 230136)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
MAKE_TIME(4, 5, 6.0) AS "datetime.time(4, 5, 6)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
MAKE_TIME(4, 5, 6.234567) AS "datetime.time(4, 5, 6, 234567)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
CAST('04:05:06.230136' AS TIME) AS "datetime.time(4, 5, 6, 230136)"

0 comments on commit b1407f8

Please sign in to comment.