diff --git a/src/pgduckdb_types.cpp b/src/pgduckdb_types.cpp index fb1c1d0..2c1d743 100644 --- a/src/pgduckdb_types.cpp +++ b/src/pgduckdb_types.cpp @@ -230,6 +230,22 @@ ConvertIntervalDatum(const duckdb::Value &value) { return IntervalPGetDatum(pg_interval); } +static Datum +ConvertTimeDatum(const duckdb::Value &value) { + std::string value_str = value.ToString(); + Datum pg_time = + DirectFunctionCall3(time_in, CStringGetDatum(value_str.c_str()), ObjectIdGetDatum(TIMEOID), Int32GetDatum(-1)); + return pg_time; +} + +static Datum +ConvertTimeTzDatum(const duckdb::Value &value) { + std::string value_str = value.ToString(); + Datum pg_timetz = DirectFunctionCall3(timetz_in, CStringGetDatum(value_str.c_str()), ObjectIdGetDatum(TIMETZOID), + Int32GetDatum(-1)); + return pg_timetz; +} + inline Datum ConvertTimestampDatum(const duckdb::Value &value) { // Extract raw int64_t value of timestamp @@ -794,6 +810,14 @@ ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col slot->tts_values[col] = ConvertDateDatum(value); break; } + case TIMEOID: { + slot->tts_values[col] = ConvertTimeDatum(value); + break; + } + case TIMETZOID: { + slot->tts_values[col] = ConvertTimeTzDatum(value); + break; + } case TIMESTAMPOID: { slot->tts_values[col] = ConvertTimestampDatum(value); break; @@ -1095,6 +1119,10 @@ GetPostgresDuckDBType(const duckdb::LogicalType &type) { return type.IsJSONType() ? JSONOID : VARCHAROID; case duckdb::LogicalTypeId::DATE: return DATEOID; + case duckdb::LogicalTypeId::TIME: + return TIMEOID; + case duckdb::LogicalTypeId::TIME_TZ: + return TIMETZOID; case duckdb::LogicalTypeId::TIMESTAMP: case duckdb::LogicalTypeId::TIMESTAMP_SEC: case duckdb::LogicalTypeId::TIMESTAMP_MS: diff --git a/test/regression/expected/test_all_types.out b/test/regression/expected/test_all_types.out index a4a2c7e..aade977 100644 --- a/test/regression/expected/test_all_types.out +++ b/test/regression/expected/test_all_types.out @@ -5,8 +5,6 @@ FROM test_all_types() SELECT * exclude( tinyint, -- PG14 outputs this differently currently varint, - TIME, - time_tz, bit, small_enum, medium_enum, @@ -40,10 +38,12 @@ usmallint | 0 uint | 0 ubigint | 0 date | 07-14-5881580 +time | 00:00:00 timestamp | Sun Jan 10 08:01:49.551616 294247 timestamp_s | Sun Jan 10 08:01:49.551616 294247 timestamp_ms | Sun Jan 10 08:01:49.551616 294247 timestamp_ns | Wed Sep 22 00:00:00 1677 +time_tz | 00:00:00+15:59:59 timestamp_tz | Sun Jan 10 00:01:49.551616 294247 PST float | -3.4028235e+38 double | -1.7976931348623157e+308 @@ -72,10 +72,12 @@ usmallint | 65535 uint | 4294967295 ubigint | 18446744073709551615 date | 07-10-5881580 +time | 24:00:00 timestamp | Sun Jan 10 04:00:54.775806 294247 timestamp_s | Sun Jan 10 04:00:54 294247 timestamp_ms | Sun Jan 10 04:00:54.775 294247 timestamp_ns | Fri Apr 11 23:47:16.854775 2262 +time_tz | 24:00:00-15:59:59 timestamp_tz | Sat Jan 09 20:00:54.775806 294247 PST float | 3.4028235e+38 double | 1.7976931348623157e+308 @@ -104,10 +106,12 @@ usmallint | uint | ubigint | date | +time | timestamp | timestamp_s | timestamp_ms | timestamp_ns | +time_tz | timestamp_tz | float | double | diff --git a/test/regression/sql/test_all_types.sql b/test/regression/sql/test_all_types.sql index 448232a..c1ce670 100644 --- a/test/regression/sql/test_all_types.sql +++ b/test/regression/sql/test_all_types.sql @@ -5,8 +5,6 @@ FROM test_all_types() SELECT * exclude( tinyint, -- PG14 outputs this differently currently varint, - TIME, - time_tz, bit, small_enum, medium_enum,