drizzle-team / drizzle-team/drizzle-orm

[BUG]: Schema adds NULLS LAST without specifying it

Open
#5,312 1 comment 2 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

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

0.45.1

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

0.31.8

### Other packages

_No response_

### Describe the Bug

When I create an index that uses desc, like this one:
```typescript
index().on(t.userId, t.clearedFromFeed, t.createdAt.desc()).concurrently()
```

It adds "NULLS LAST" to the schema, which seems undesirable if it's not specifically set.

Here's what it creates:

```sql
CREATE INDEX "items_user_id_clearedFromFeed_created_at_index" ON public.items USING btree (user_id, "clearedFromFeed", created_at DESC NULLS LAST)
```

I expected it to be

```sql
CREATE INDEX "items_user_id_clearedFromFeed_created_at_index" ON public.items USING btree (user_id, "clearedFromFeed", created_at DESC)
```

The 'NULLS LAST' degraded the query performance and it took a while to debug. There's also no way to order by NULLS LAST, so I had to resort to this:

```typescript
.orderBy(sql`${items.createdAt} DESC NULLS LAST`);
```

Which is okay for now. Just unexpected behavior!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.