Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: sql placeholder with an array throws an error #2872

Open
Wisieneu opened this issue Aug 28, 2024 · 0 comments
Open

[BUG]: sql placeholder with an array throws an error #2872

Wisieneu opened this issue Aug 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Wisieneu
Copy link

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

No response

Describe the Bug

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"]
})

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.
It would also be awesome if this case was handled by the ORM, so that no workarounds are needed.

Expected behavior

  • array is converted by the prepared query into something acceptable by postgres sql statement
  • the documentation describes how to handle more cases in this place: https://orm.drizzle.team/docs/perf-queries#prepared-statement
  • i can pass a literal into the sql.placeholder to specify the expected variable type maybe? like:
 sql.placeholder<string[]>("postIds")

Environment & setup

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant