I'm trying to pass a Go variable inside db.Exec:
pinakas := "dokimi03"
crTable := `CREATE TABLE ? (id bigint(20) NOT NULL AUTO_INCREMENT, username varchar(100) NOT NULL, password varchar(100) NOT NULL, email varchar(100) NOT NULL, PRIMARY KEY (id));`
_, errCreate := db.Exec(crTable, pinakas)
if errCreate != nil {
log.Println(errCreate)
}
The error I get from MySQL when I run the code is:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? (id bigint(20) NOT NULL AUTO_INCREMENT, username varchar(100) NOT NULL, passwo' at line 1
The code runs if I substitute ? with dokimi03, the table name (and remove pinakas var of course).
I've searched the docs, ? seems to be the proper character to represent variables on Go-MySQL. What am I missing?
?is for values. Table names, column names, etc. are NOT values, they are identifiers. You can't use?for table names.