Skip to content

Commit

Permalink
detect that the NUMERIC was converted to a DOUBLE, treat it as such
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishj committed May 6, 2024
1 parent 0bbc240 commit cedd577
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/quack_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace quack {
constexpr int32_t QUACK_DUCK_DATE_OFFSET = 10957;
constexpr int64_t QUACK_DUCK_TIMESTAMP_OFFSET = INT64CONST(10957) * USECS_PER_DAY;

static void ConvertDouble(TupleTableSlot *slot, double value, idx_t col) {
slot->tts_tupleDescriptor->attrs[col].atttypid = FLOAT8OID;
slot->tts_tupleDescriptor->attrs[col].attbyval = true;
memcpy(&slot->tts_values[col], (char *)&value, sizeof(double));
}

void
ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col) {
Oid oid = slot->tts_tupleDescriptor->attrs[col].atttypid;
Expand Down Expand Up @@ -63,12 +69,15 @@ ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col
}
case FLOAT8OID: {
double result_double = value.GetValue<double>();
slot->tts_tupleDescriptor->attrs[col].atttypid = FLOAT8OID;
slot->tts_tupleDescriptor->attrs[col].attbyval = true;
memcpy(&slot->tts_values[col], (char *)&result_double, sizeof(double));
ConvertDouble(slot, result_double, col);
break;
}
case NUMERICOID: {
if (value.type().id() == duckdb::LogicalTypeId::DOUBLE) {
auto result_double = value.GetValue<double>();
ConvertDouble(slot, result_double, col);
break;
}
elog(ERROR, "Unsupported quack (Postgres) type: %d", oid);
break;
}
Expand Down

0 comments on commit cedd577

Please sign in to comment.