Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public ColumnType convert(Column column) {
boolean isNullable = !column.isKeyFlag() && column.isNullable();
final LogicalTypeParam logicalTypeParam =
LogicalTypeParam.of(isNullable, length, column.getPrecision(), column.getScale());
if (type.contains("numeric") || type.contains("decimal")) {
int intValue = column.getPrecision().intValue();
if (intValue > 38) {
if (type.contains("numeric") || type.contains("decimal") || type.contains("money")) {
Integer precision = column.getPrecision();
if (Asserts.isNotNull(precision) && precision > 38) {
return ColumnType.of(DataTypes.STRING, DataTypes.STRING.copyLogicalType(logicalTypeParam));
}
return ColumnType.of(DataTypes.DECIMAL, DataTypes.DECIMAL.copyLogicalType(logicalTypeParam));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

import org.dinky.data.model.Column;
import org.dinky.data.model.Table;
import org.dinky.data.types.ColumnType;
import org.dinky.data.types.DataTypes;
import org.dinky.metadata.convert.PostgreSqlTypeConvert;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -145,4 +147,19 @@ void getCreateTableSql() {
+ "COMMENT ON COLUMN \"public\".\"user\".\"register_time\" IS '注册时间';\n";
assertEquals(expect, tableDDL);
}

@Test
void convertMoneyTypeToDecimal() {
Column moneyColumn = Column.builder()
.name("balance")
.type("money")
.precision(19)
.scale(2)
.isNullable(true)
.build();

ColumnType columnType = new PostgreSqlTypeConvert().convert(moneyColumn);

assertEquals(DataTypes.DECIMAL, columnType.getValue());
}
}
Loading