-1

I have the following sql code:

sqlStatement := `INSERT INTO listings (listing_key,lat,long)
                     VALUES(?,?,?)`

However, long is a reserved keyword in mysql so i need to escape the column. As in:

sqlStatement := `INSERT INTO listings (listing_key,lat,`long`)
                     VALUES(?,?,?)`

but that breaks the sql statement.

not sure how to resolve. theres a ton more columns so i need to use the multi line tick.

somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • Can't you escape the tick with backslash? – Nick Oct 24 '19 at 23:53
  • 1
    Use “ (double quote) instead for identifiers. This is standard SQL syntax and supported in MySQL with ANSI_QUOTES. https://dev.mysql.com/doc/refman/8.0/en/identifiers.html - issue deflected! – user2864740 Oct 25 '19 at 00:12

1 Answers1

2

Both ugly, but you can do one of:

statement:=`INSERT INTO listings (listing_key,lat,`+"`long`)"

or:

statement:=strings.Replace(`INSERT INTO listings (listing_key,lat,^long^)`,"^","`",-1)
Burak Serdar
  • 46,455
  • 3
  • 40
  • 59