sql placeholder with an array throws an error

when executing this code:
const prepQuery = db
.select()
.from(table)
.where(inArray(table.postId, sql.placeholder("postIds")))
.prepare("prepquery");

const result = await prepQuery.execute({
postIds: ["esaeasdas", "esaeasdas", "esaeasdas"]
})
const prepQuery = db
.select()
.from(table)
.where(inArray(table.postId, sql.placeholder("postIds")))
.prepare("prepquery");

const result = await prepQuery.execute({
postIds: ["esaeasdas", "esaeasdas", "esaeasdas"]
})
Drizzle throws an error: syntax error at or near \"$1\. The code works when I execute the prepared query without the sql.placeholder, hardcoding an argument inside prepQuery - the error is not reproduced anyway else. Do I need to pass the array of strings there differently? I tried converting it into a string, but that does not work neither.
1 Reply
Angelelz
Angelelz4mo ago
Prepared statements don’t work with arrays They only save one placeholder An array need one placeholder per item
Want results from more Discord servers?
Add your server