I'm doing a MySQL query in an aws-lambda function.
I'd like to know if it's possible to have a js function inside an SQL query where it would use a selected item as it's parameter. like this
Left join users user
WHERE ( student.id = user.id AND student.age = '${Process_minimum_Age('user.dateOfBirth')}')
or a more realistic example
WHERE ( currentLocation = user.location AND currentTime = '${ moment().tz('user.timezone')}' )
I'm not sure how to refer back to SQL inside the parameter, when I try it I get the following error.
"errorMessage": "ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (latin1_swedish_ci,NUMERIC) for operation '='"
UPDATE:
Thanks to @H. Figueiredo who kindly and promptly helped me to figure what the problem and gave me the right answer.
Since I was using template literals and the fact that user.timezone parameter was returning a string I had to wrap it with the following escape quote method .. '${moment().tz(
`\'us.timezone\'`)
(it's a bit of a challenge escaping backticks here too :)