escape ticks in golang sql statement [duplicate]

22
October 25, 2019, at 3:00 PM

This question already has an answer here:

  • How to escape back ticks 5 answers

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.

Answer 1

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)
READ ALSO
Error when foreign referencing in mySQL (Error 3780)

Error when foreign referencing in mySQL (Error 3780)

I am making two tables and I want the personOne column from table b to reference the person column on table a, but for some reason it doesn't work

31
why is mysql refusing local connections

why is mysql refusing local connections

I'm trying to use the (slightly older version of) MySQL C++ connector (see here) to open up a connection to a database and write stuff to itMy code works on my local Ubuntu 18

35
SQL - Check if a column auto increments

SQL - Check if a column auto increments

I am trying to run a query to check if a column auto incrementsI can check type, default value, if it's nullable or not, etc

29
Create a list of actor pairs along with the number of films that they have in common

Create a list of actor pairs along with the number of films that they have in common

have this query so far for the above questionIm a student who is just starting so any help would be appreciated

51