Skip to content

Commit

Permalink
varbit
Browse files Browse the repository at this point in the history
  • Loading branch information
dentiny committed Feb 26, 2025
1 parent f7997b4 commit ab13c91
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/pgduckdb_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ struct DecimalConversionDouble {
}
};

static Datum
ConvertVarbitDatum(const duckdb::Value &value) {
const std::string value_str = value.ToString();
Datum pg_varbit = DirectFunctionCall3(varbit_in, CStringGetDatum(value_str.c_str()), ObjectIdGetDatum(VARBITOID),
Int32GetDatum(-1));
return pg_varbit;
}

static inline Datum
ConvertBoolDatum(const duckdb::Value &value) {
return value.GetValue<bool>();
Expand Down Expand Up @@ -765,6 +773,10 @@ ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col
Oid oid = slot->tts_tupleDescriptor->attrs[col].atttypid;

switch (oid) {
case VARBITOID: {
slot->tts_values[col] = ConvertVarbitDatum(value);
break;
}
case BOOLOID:
slot->tts_values[col] = ConvertBoolDatum(value);
break;
Expand Down Expand Up @@ -1071,6 +1083,8 @@ GetPostgresArrayDuckDBType(const duckdb::LogicalType &type) {
Oid
GetPostgresDuckDBType(const duckdb::LogicalType &type) {
switch (type.id()) {
case duckdb::LogicalTypeId::BIT:
return VARBITOID;
case duckdb::LogicalTypeId::BOOLEAN:
return BOOLOID;
case duckdb::LogicalTypeId::TINYINT:
Expand Down
4 changes: 3 additions & 1 deletion test/regression/expected/test_all_types.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SELECT * exclude(
varint,
TIME,
time_tz,
bit,
small_enum,
medium_enum,
large_enum,
Expand Down Expand Up @@ -55,6 +54,7 @@ uuid | 00000000-0000-0000-0000-000000000000
interval | @ 0
varchar | 🦆🦆🦆🦆🦆🦆
blob | thisisalongblob\000withnullbytes
bit | 0010001001011100010101011010111
int_array | {}
double_array | {}
date_array | {}
Expand Down Expand Up @@ -87,6 +87,7 @@ uuid | ffffffff-ffff-ffff-ffff-ffffffffffff
interval | @ 83 years 3 mons 999 days 16 mins 39.999999 secs
varchar | goo
blob | \000\000\000a
bit | 10101
int_array | {42,999,NULL,NULL,-42}
double_array | {42,NaN,Infinity,-Infinity,NULL,-42}
date_array | {01-01-1970,07-11-5881580,07-13-5881580,NULL,05-12-2022}
Expand Down Expand Up @@ -119,6 +120,7 @@ uuid |
interval |
varchar |
blob |
bit |
int_array |
double_array |
date_array |
Expand Down
1 change: 0 additions & 1 deletion test/regression/sql/test_all_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SELECT * exclude(
varint,
TIME,
time_tz,
bit,
small_enum,
medium_enum,
large_enum,
Expand Down

0 comments on commit ab13c91

Please sign in to comment.