diff --git a/importSampleData/app/main.go b/importSampleData/app/main.go index e45e33e159f8636f8bdc5156b3b9b0947453bab4..3589c8c2a98f31e78c4dac3496f804605a0b2314 100644 --- a/importSampleData/app/main.go +++ b/importSampleData/app/main.go @@ -628,7 +628,7 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i buffer.WriteString(",") for _, field := range subTableInfo.config.Fields { - buffer.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)])) + buffer.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)],field.Type)) buffer.WriteString(",") } @@ -708,7 +708,10 @@ func executeBatchInsert(insertSql string, connection *sql.DB) int64 { return affected } -func getFieldValue(fieldValue interface{}) string { +func getFieldValue(fieldValue interface{},fieldtype interface{}) string { + if fieldtype == "timestamp" || fieldtype == "bigint" { + return fmt.Sprintf("%v", fieldValue) + } return fmt.Sprintf("'%v'", fieldValue) } diff --git a/importSampleData/config/cfg.toml b/importSampleData/config/cfg.toml index 52a5d5f3169d21ce17039ead956250a636b37a01..545bab071ad66af2f59447b3449c6606e2ff1078 100644 --- a/importSampleData/config/cfg.toml +++ b/importSampleData/config/cfg.toml @@ -18,6 +18,8 @@ tags = [ fields = [ # 字段列表,name 为字段名称,type 为字段类型 + # 除主键外,其他field如果也要设置为timestamp,可以是type ="timestamp" 类型,此时value可同时支持'2006-01-02 15:04:05.000'和millisecond格式 + # 也可以是type = "bigint",此时value只支持millisecond格式 { name = "ts", type = "timestamp" }, { name = "temperature", type = "int" }, { name = "humidity", type = "float" },