Closed viniciusbitt closed 4 years ago
I have an array of integers and to use with WHERE IN, I separate by comma
const in_categories = (await getCategoryTreeIDs(categoryID)).join(','); let query = SQL`SELECT * FROM products WHERE CategoryID IN (${in_categories})`
After execute the query, seeing the MySQL log the query looks like this: SELECT * FROM products CategoryID IN ('1, 50, 51')
SELECT * FROM products CategoryID IN ('1, 50, 51')
And it's not what I want, I need it to be a list, not a string. So, I tried to do it like this:
const in_categories = (await getCategoryTreeIDs(categoryID)).map(id =>"${id}").join(',');
const in_categories = (await getCategoryTreeIDs(categoryID)).map(id =>
).join(',');
Result (that also didn't work): IN ('\'\"1\"\',\'\"50\"\',\'\"51\"\'')
IN ('\'\"1\"\',\'\"50\"\',\'\"51\"\'')
I have an array of integers and to use with WHERE IN, I separate by comma
After execute the query, seeing the MySQL log the query looks like this:
SELECT * FROM products CategoryID IN ('1, 50, 51')
And it's not what I want, I need it to be a list, not a string. So, I tried to do it like this:
const in_categories = (await getCategoryTreeIDs(categoryID)).map(id =>
"${id}").join(',');
Result (that also didn't work):
IN ('\'\"1\"\',\'\"50\"\',\'\"51\"\'')