Skip to content

Instantly share code, notes, and snippets.

@methane

methane/main.go Secret

Created August 24, 2024 05:39
Show Gist options
  • Save methane/8f7bf5c84705246ab7c8da3eb5889820 to your computer and use it in GitHub Desktop.
Save methane/8f7bf5c84705246ab7c8da3eb5889820 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func must(err error) {
if err != nil {
panic(err)
}
}
func main() {
var (
v1, v2 any
db *sql.DB
)
db, err := sql.Open("mysql", "root@tcp(127.0.0.1:3306)/test")
must(err)
err = db.QueryRow(`select sum(JSON_EXTRACT(name, '$.hoge1.fuga1')) as piyo from users`).Scan(&v1)
fmt.Printf("%T, %v, %v\n", v1, v1, err) // output: 100000, nil
err = db.QueryRow(`
select sum(JSON_EXTRACT(name, '$.hoge2.fuga2')) as piyo from users`).Scan(&v2)
fmt.Printf("%T, %v, %v\n", v1, v2, err) // output: 0, Scan error on column index 0, name "piyo": converting driver.Value type float64 ("1e+06") to a int64: invalid syntax
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment