drizzle-team / drizzle-team/drizzle-orm
[BUG]: sql placeholder with an array throws an error
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### 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:
```ts
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:
```ts
sql.placeholder("postIds")
```
### Environment & setup
_No response_
Contributor guide
Research direction
Start by reproducing the prepared-query example using sql.placeholder, inArray, prepare, and execute against PostgreSQL, then inspect the prepared-statement documentation at the linked URL. Done means an array placeholder works as expected and the documentation explains supported array handling and any type syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100