Skip to content
Discussion options

You must be logged in to vote

However, when I run the queries using this driver, the LastInsertId() returns THE LAST inserted row.

REALLY?

// https://github.com/go-sql-driver/mysql/discussions/1717package main import ( "database/sql""fmt" _ "github.com/go-sql-driver/mysql" ) // Use example in https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_last-insert-idfuncmain(){db, err:=sql.Open("mysql", "root:my-secret-pw@tcp(127.0.0.1:3306)/test") iferr!=nil{panic(err) } res, err:=db.Exec("INSERT INTO t VALUES (NULL, 'Bob')") iferr!=nil{panic(err) } last, err:=res.LastInsertId() fmt.Printf("last insert id: %d\n", last) res, err=db.Exec("INSERT INTO t VALU…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stephenafamo
Comment options

Answer selected bystephenafamo
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@stephenafamo@methane