diff --git a/src/pgduckdb_types.cpp b/src/pgduckdb_types.cpp index fb1c1d0..0576087 100644 --- a/src/pgduckdb_types.cpp +++ b/src/pgduckdb_types.cpp @@ -337,6 +337,16 @@ ConvertNumeric(const duckdb::Value &ddb_value, idx_t scale, NumericVar &result) static Datum ConvertNumericDatum(const duckdb::Value &value) { auto value_type_id = value.type().id(); + + // Special handle duckdb VARINT type. + if (value.type().id() == duckdb::LogicalTypeId::VARINT) { + std::string value_str = value.ToString(); + Datum pg_numeric = DirectFunctionCall3(numeric_in, CStringGetDatum(value_str.c_str()), + ObjectIdGetDatum(InvalidOid), Int32GetDatum(-1)); + return pg_numeric; + } + + // Special handle duckdb DOUBLE TYPE. if (value_type_id == duckdb::LogicalTypeId::DOUBLE) { return ConvertDoubleDatum(value); } @@ -1112,6 +1122,8 @@ GetPostgresDuckDBType(const duckdb::LogicalType &type) { return NUMERICOID; case duckdb::LogicalTypeId::UUID: return UUIDOID; + case duckdb::LogicalTypeId::VARINT: + return NUMERICOID; case duckdb::LogicalTypeId::LIST: { const duckdb::LogicalType *duck_type = &type; while (duck_type->id() == duckdb::LogicalTypeId::LIST) { diff --git a/test/regression/expected/test_all_types.out b/test/regression/expected/test_all_types.out index a4a2c7e..1c40a66 100644 --- a/test/regression/expected/test_all_types.out +++ b/test/regression/expected/test_all_types.out @@ -4,7 +4,6 @@ SELECT * FROM duckdb.query($$ FROM test_all_types() SELECT * exclude( tinyint, -- PG14 outputs this differently currently - varint, TIME, time_tz, bit, @@ -28,7 +27,7 @@ SELECT * exclude( nested_int_array, -- The nested array has different lengths, which is not possible in PG ) $$) --[ RECORD 1 ]---+------------------------------------------------------------------------------------------------------------------------------------- +-[ RECORD 1 ]---+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool | f smallint | -32768 int | -2147483648 @@ -39,6 +38,7 @@ utinyint | 0 usmallint | 0 uint | 0 ubigint | 0 +varint | -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368 date | 07-14-5881580 timestamp | Sun Jan 10 08:01:49.551616 294247 timestamp_s | Sun Jan 10 08:01:49.551616 294247 @@ -60,7 +60,7 @@ double_array | {} date_array | {} timestamp_array | {} varchar_array | {} --[ RECORD 2 ]---+------------------------------------------------------------------------------------------------------------------------------------- +-[ RECORD 2 ]---+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool | t smallint | 32767 int | 2147483647 @@ -71,6 +71,7 @@ utinyint | 255 usmallint | 65535 uint | 4294967295 ubigint | 18446744073709551615 +varint | 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368 date | 07-10-5881580 timestamp | Sun Jan 10 04:00:54.775806 294247 timestamp_s | Sun Jan 10 04:00:54 294247 @@ -92,7 +93,7 @@ double_array | {42,NaN,Infinity,-Infinity,NULL,-42} date_array | {01-01-1970,07-11-5881580,07-13-5881580,NULL,05-12-2022} timestamp_array | {"Thu Jan 01 00:00:00 1970","Sun Jan 10 04:00:54.775807 294247","Sun Jan 10 04:00:54.775809 294247",NULL,"Thu May 12 16:23:45 2022"} varchar_array | {🦆🦆🦆🦆🦆🦆,goose,NULL,""} --[ RECORD 3 ]---+------------------------------------------------------------------------------------------------------------------------------------- +-[ RECORD 3 ]---+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool | smallint | int | @@ -103,6 +104,7 @@ utinyint | usmallint | uint | ubigint | +varint | date | timestamp | timestamp_s | diff --git a/test/regression/sql/test_all_types.sql b/test/regression/sql/test_all_types.sql index 448232a..1c074a7 100644 --- a/test/regression/sql/test_all_types.sql +++ b/test/regression/sql/test_all_types.sql @@ -4,7 +4,6 @@ SELECT * FROM duckdb.query($$ FROM test_all_types() SELECT * exclude( tinyint, -- PG14 outputs this differently currently - varint, TIME, time_tz, bit,