Closed richardvk closed 1 year ago
When you have a dash in a tag, the Go sqlx package's name mapper treats it as a word separator. Therefore, "NS-Var-ID" is being interpreted as three separate words: "NS", "Var", and "ID". Unfortunately, it is not possible to escape the dashes in the tags.
If you can, change the column name to not include dashes.
Alternatively
q := "INSERT INTO table (`NS-Var-ID`) VALUES (?)"
_, err := dstDbh.Exec(q, d.NSVarID)
@richardvk if you have no more questions, please close this issue.
Thanks for the help and explanation. If anyone else is interested, I solved this with
SELECT NS-Var-ID AS ns_var_id FROM table
so that i could create my struct as
NSVarID string `db:"ns_var_id"`
This then worked fine, bearing in mind I specifically wanted to use NamedExec to do batch inserts with a slice of db rows:
q := "INSERT INTO table (`NS-Var-ID`) VALUES (:ns_var_id)"
_, err := dstDbh.NamedExec(q, d)
I have a database column defined as :
I have a struct with
Trying to use NamedExec with this name fails, something like this:
I have tried all sorts of quoting, but I am unable to find anything that works. The biggest downside is that Im unable to use batch inserting which seems to only be supported by NamedExec.