From 5b379d5a59e5f0b5d422e7cfcdc2222b7ec0ee89 Mon Sep 17 00:00:00 2001 From: Jupiter <1040104807@qq.com> Date: Sat, 20 Nov 2021 20:00:18 +0800 Subject: [PATCH] insert datas contains multiple timestamp columns, but this tool transfer it to 'char' and pops up errors. (#8634) * insert datas contains multiple timestamp columns, but this tool transfer it to 'char' and pops up errors. * insert datas contains multiple timestamp columns, but this tool transfer it to 'char' and pops up errors. * insert datas contains multiple timestamp columns, but this tool transfer it to 'char' and pops up errors. --- importSampleData/app/main.go | 7 +++++-- importSampleData/config/cfg.toml | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/importSampleData/app/main.go b/importSampleData/app/main.go index e45e33e159..3589c8c2a9 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 52a5d5f316..545bab071a 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" }, -- GitLab