转到:未使用的变量

I am trying to execute a SQL statement in the code below. However, sqlRes is unused and therefore cannot be compiled. I do not need the variable, but I need to declare it because Exec() returns multiple values.

How do I approach this?

stmt, err := db.Prepare("INSERT person SET name=?")
sqlRes, err := stmt.Exec(person.Name)

Replace sqlRes with the blank identifier (_). From the spec:

The blank identifier provides a way to ignore right-hand side values in an assignment:

_ = x       // evaluate x but ignore it
x, _ = f()  // evaluate f() but ignore second result value

Example:

stmt, err := db.Prepare("INSERT person SET name=?")
_, err = stmt.Exec(person.Name)