问题是:
我在PostgreSQL中有一个数据库,我在Golang中读取了所有数据并从中创建数组。问题是:如何将这些数组放入influxdb?

最佳答案

package main

import (
"database/sql"
"log"
_ "./pq"
"fmt"

)

type DbInfo struct {
id string
person_id int
timestamp int
age string
gender string
attention string
interest int
happines int
surprise int
anger int
disgust int
fear string
sadness int
neutrall string

}

var DBObject DbInfo
var DbArray []DbInfo




func main() {


db, err := sql.Open("****", "postgres://postgres:********/cam?
sslmode=disable")
if err != nil {
    log.Fatal(err)
}
defer db.Close()
rows, err := db.Query(`SELECT avg(age), avg(id), avg(neutrall),avg(fear)
 FROM public.stat`) //stringTimeDayAgoQuery )
if err != nil {
    log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
    //err := rows.Scan(&DBObject.id, &DBObject.person_id,
 &DBObject.timestamp,&DBObject.age,
 &DBObject.gender,&DBObject.attention,&DBObject.interest,&DBObject.happines,

   &DBObject.surprise,&DBObject.anger,&DBObject.disgust,&DBObject.fear,
   &DBObject.sadness,&DBObject.neutrall)
    err := rows.Scan(&DBObject.age,&DBObject.id,&DBObject.neutrall,
   &DBObject.fear)

    if err != nil {
        log.Fatal(err)
    }
    DbArray = append(DbArray, DBObject)
}
fmt.Println(DbArray)

}
在此代码中。我从postgreSQL读取数据。我将其读取为数组,现在我想将输出导入Influxdb。因为我想使用Grafana,所以它不适用于postgresql。

关于postgresql - 如何从golang数组向influxdb写入数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45473410/

10-16 08:09
查看更多