diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py index 506c510e5a27..f91fa4ce8ceb 100644 --- a/ibis/backends/duckdb/registry.py +++ b/ibis/backends/duckdb/registry.py @@ -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) diff --git a/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-date/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-date/out.sql new file mode 100644 index 000000000000..13cadbfb002c --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-date/out.sql @@ -0,0 +1,2 @@ +SELECT + MAKE_DATE(2023, 4, 7) AS "datetime.date(2023, 4, 7)" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-time/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-time/out.sql new file mode 100644 index 000000000000..acc41e239c5d --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-time/out.sql @@ -0,0 +1,2 @@ +SELECT + MAKE_TIME(4, 5, 6) AS "datetime.time(4, 5, 6, 230136)" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-timestamp/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-timestamp/out.sql new file mode 100644 index 000000000000..aff9e45a7213 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_temporal_literals/duckdb-timestamp/out.sql @@ -0,0 +1,2 @@ +SELECT + MAKE_TIMESTAMP(1680854706230136) AS "datetime.datetime(2023, 4, 7, 4, 5, 6, 230136)" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_temporal/test_time_literals/0-duckdb/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/0-duckdb/out.sql new file mode 100644 index 000000000000..fab689db2dde --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/0-duckdb/out.sql @@ -0,0 +1,2 @@ +SELECT + MAKE_TIME(4, 5, 6.0) AS "datetime.time(4, 5, 6)" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_temporal/test_time_literals/234567-duckdb/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/234567-duckdb/out.sql new file mode 100644 index 000000000000..ac6ca0601526 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/234567-duckdb/out.sql @@ -0,0 +1,2 @@ +SELECT + MAKE_TIME(4, 5, 6.234567) AS "datetime.time(4, 5, 6, 234567)" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_temporal/test_time_literals/trino/out.sql b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/trino/out.sql new file mode 100644 index 000000000000..2bb8fe68e333 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_temporal/test_time_literals/trino/out.sql @@ -0,0 +1,2 @@ +SELECT + CAST('04:05:06.230136' AS TIME) AS "datetime.time(4, 5, 6, 230136)" \ No newline at end of file