Skip to content

Commit

Permalink
fix(clickhouse): decimal field
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed May 24, 2024
1 parent 4f4271c commit 06d179d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backends/clickhouse/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ type SDecimalColumn struct {
// ColType implementation of SDecimalColumn for IColumnSpec
func (c *SDecimalColumn) ColType() string {
str := c.SClickhouseBaseColumn.ColType()
return fmt.Sprintf("%s(%d, %d)", str, c.width, c.Precision)
if str == "Decimal" {
return fmt.Sprintf("%s(%d, %d)", str, c.width, c.Precision)
}
return fmt.Sprintf("%s(%d)", str, c.Precision)
}

// IsNumeric implementation of SDecimalColumn for IColumnSpec
Expand Down
8 changes: 8 additions & 0 deletions backends/clickhouse/columninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func (info *sSqlColumnInfo) getTagmap() map[string]string {
}
tagmap[sqlchemy.TAG_DEFAULT] = defVal
}
sqlType := info.getType()
if strings.HasPrefix(sqlType, "Decimal") {
re := regexp.MustCompile(`Decimal\((\d+),\s*(\d+)\)`)
match := re.FindStringSubmatch(sqlType)
if len(match) == 3 {
tagmap[sqlchemy.TAG_WIDTH], tagmap[sqlchemy.TAG_PRECISION] = match[1], match[2]
}
}
return tagmap
}

Expand Down

0 comments on commit 06d179d

Please sign in to comment.