Issue
I have recently struck an issue with mysql using serverless-mysql
in TypeScript where potentially my query is incorrect? I am using the following to create the query:
export default async function ExcuteQuery(query: any, values: any) {
try {
const results = await db.query(query, values);
await db.end();
return results;
} catch (error: any) {
throw new Error(error.message + error.stack)
}
}
let ids: BigInt[] = [222222222222222222222, 3333333333333333333333, 444444444444444444444]
ExcuteQuery("SELECT * FROM servers WHERE id IN (?)", [ids.join()])
Which returned an empty array with no row data inside.
However, when I tried using the query inside phpmyadmin, like so:
"SELECT * FROM servers WHERE id IN (222222222222222222222, 3333333333333333333333, 444444444444444444444)"
It returned the rows as I would like them, no troubles. Does this mean I am doing something wrong with the parameter data that I am passing into that query? Is it a type cast issue? I am more then happy to elaborate if that was not clear, just feel free to comment!
I appreciate any responses I get in advance, thank you!
I have attempted to change the parameter data using attempts like:
[ids.join(', ')]
[`(${ids.join()})`]
However, none of those seemed to work either.
Solution
SELECT servers.*
FROM servers
JOIN JSON_TABLE(CONCAT('[', ?, ']'),
'$[*]' COLUMNS (id BIGINT PATH '$')) criteria USING (id)
Answered By - Akina
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.