I am trying to use named parameter query in golang as follows:
stmt, err := db.Prepare("insert into users(name, email) values(@name, @email)")
if err != nil {
//error handling
}
res, err := stmt.Exec(sql.Named("name", name), sql.Named("email", email))
if err != nil {
//error: sql: expected 0 arguments, got 2
}
I get the following error: "sql: expected 0 arguments, got 2".
What is correct way to write this query?
Go needs to support every kind of SQL server - and not all SQL servers support named parameters. The servers that do support them do it with a variety of quirks and "gotchas". But they all support positional parameters just fine.
However there is an open issue for it for the mysql-driver: https://github.com/go-sql-driver/mysql/issues/561
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With