好使啊,以下是我测试的代码,可以正常执行
package main
import (
"database/sql"
"fmt"
_ "
github.com/lib/pq"
)
func main() {
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
"localhost", 5432, "postgres", "postgres", "postgres")
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
defer db.Close()
err = db.Ping()
if err != nil {
panic(err)
}
sql := "insert into testupsert values ($1,$2,$3) on conflict (uid) do update set total=testupsert.total+1,what = EXCLUDED.what"
_,err = db.Exec(sql,1,3,3)
if err != nil{
panic(err)
}
}