drizzle-team / drizzle-team/drizzle-orm

[BUG]: I can't pass a array as a parameter of an SQL query.

Open
#1,947 4 comments 1 reaction 0 assignees View on GitHub
db/postgres improvement qb/crud
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.29.4

### What version of `drizzle-kit` are you using?

0.20.14

### Describe the Bug

I can't pass an array as a parameter of an SQL query.
Here is the code that doesn't work with drizzle-orm but works with postgres.js.

```javascript
import { sql } from 'drizzle-orm'
const arr = [6, 7, 9];
await db.execute(sql`SELECT array_length(${arr}::NUMERIC[], 1)`)
```

```bash
cannot cast type record to numeric[]
```

But with postgres.js (npm) it works
```javascript
const arr = [6, 7, 9];
const result = await client`SELECT array_length(${arr}::NUMERIC[], 1);`
```

### Expected behavior

_No response_

### Environment & setup

macOS: 14.2.1

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the JavaScript example from the issue with drizzle-orm 0.29.4 and PostgreSQL, then trace how SQL parameters are serialized for array values before execution. Done means the shown array can be passed to array_length with the numeric-array cast without the record-to-numeric[] error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.