TDengine INSERT 测试数据总是报错:Timestamp data out of range

测试数据如下:

INSERT INTO log USING dockerlog.superlog TAGS ('server01', '127.0.0.1') VALUES ('2000-01-01 00:00:00.000', '2000-01-01 00:00:00.000', '[GIN] 2000/1/1 - 00:00:00 | 200 |     136.069µs |   172.16.96.255 | POST     /data-transfer-receiving/save-to-kafka');

报错:

Timestamp data out of range

原来:我设置了 15天过期,

CREATE DATABASE log KEEP 15 DAYS 2 BLOCKS 4 UPDATE 1

因此只能插入最近15天的时间.改为:

INSERT INTO log USING superlog TAGS ('server01', '127.0.0.1') VALUES ('2020-12-30 11:01:03.000', '2020-12-30 12:01:04.000', '[GIN] 2020/12/30 - 07:09:19 | 200 |     136.069µs |   172.16.96.255 | POST     /data-transfer-receiving/save-to-kafka');
INSERT INTO log USING superlog TAGS ('server01', '127.0.0.1') VALUES (1609257600000, 1609257600000, '[GIN] 2020/12/30 - 09:57:57 | 200 |      91.578µs |   172.16.96.255 | POST     /data-transfer-receiving/save-to-kafka');

int和string的sql只要时间在15天之内,测试通过.

附go语言插入代码:

func insertMessage(module, host, tsStr, tdtsStr, message string){
	db, err := sql.Open(taosDriverName, url)
	if err != nil {
		panic(err)
	}
	defer db.Close()
	table := strings.Replace(module, "-", "_", -1 )
	sql := fmt.Sprintf("INSERT INTO %s USING superlog TAGS ('%s', '%s') VALUES (%s, %s, '%s');", table, module, host, tsStr, tdtsStr, message)
	fmt.Println("sql:",sql)
	res, err := db.Exec(sql)
	if err!=nil{
		fmt.Println("res, err:",res, err)
	}
	count, err := res.RowsAffected()
	if err!=nil{
		fmt.Println("count, err, sql:", count, err)
	}
	fmt.Println("insertMessage finish")
}

 

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐