簡體   English   中英

go-sql-driver / mysql-將float64插入mariadb(雙列)會提供不受支持的類型func()float64,即func

[英]go-sql-driver/mysql - inserting a float64 into mariadb (double column) gives unsupported type func() float64, a func

我是Go語言的新手,幾天前我剛剛開始學習並發性:-)。 我有一個不同的庫,它返回一個time.Duration類型,該類型具有Seconds,這是我想使用並存儲在數據庫中的float64精度值。

以下是我要完成的相關工作:

type pResp struct {
    address string
    rtt     time.Duration
    sent    int
    recv    int
}

stmt, err := db.Prepare("insert pings set domain = ?, packet_rtt = ?, packets_sent = ?, packets_recv = ?")
res, err := stmt.Exec(r.address, r.rtt.Seconds, r.sent, r.recv)

這是我得到的錯誤:

2019/08/26 19:57:35 sql: converting argument $2 type: unsupported type func() float64, a func
Process exiting with code: 0

MySQL中的列設置為double,應為64位...我不確定在這里哪里出錯。 這是我正在使用的庫的限制嗎? 謝謝。

看來您正在傳遞一流的函數func() float64而不是實際的float64原語。 該函數的來源是r.rtt.Seconds ,應將其作為r.rtt.Seconds()調用。 請參閱Duration.Seconds

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM