Skip to content

Commit

Permalink
Truncate to DECIMAL(38, scale) if width > 38
Browse files Browse the repository at this point in the history
  • Loading branch information
piggynl committed Sep 20, 2024
1 parent 03eaed7 commit 7ea980b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/postgres_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ LogicalType PostgresUtils::TypeToLogicalType(optional_ptr<PostgresTransaction> t
} else if (pgtypename == "numeric") {
auto width = ((type_info.type_modifier - sizeof(int32_t)) >> 16) & 0xffff;
auto scale = (((type_info.type_modifier - sizeof(int32_t)) & 0x7ff) ^ 1024) - 1024;
if (type_info.type_modifier == -1 || width < 0 || scale < 0 || width > 38) {
if (type_info.type_modifier == -1 || width < 0 || scale < 0) {
// fallback to double
postgres_type.info = PostgresTypeAnnotation::NUMERIC_AS_DOUBLE;
return LogicalType::DOUBLE;
}
if (width > 38) {
postgres_type.info = PostgresTypeAnnotation::NUMERIC_TRUNCATE;
return LogicalType::DECIMAL(38, scale);
}
return LogicalType::DECIMAL(width, scale);
} else if (pgtypename == "char" || pgtypename == "bpchar") {
postgres_type.info = PostgresTypeAnnotation::FIXED_LENGTH_CHAR;
Expand Down

0 comments on commit 7ea980b

Please sign in to comment.