drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: nulls first/last support for order by asc & desc in postgres

Open
#1,699 5 comments 18 reactions 0 assignees View on GitHub
enhancement qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

currently the `asc` & `desc` do not support order of nulls (first/last)

by default in postgres the nulls come first for `desc` and last for `asc` orders, which is quite stupid to be honest but anyways,

I needed that so build my own wrappers for it below but I think this should be a inbuild thing

```ts
import { type AnyColumn, type SQLWrapper, sql } from "drizzle-orm"

export function asc(column: SQLWrapper | AnyColumn, nullsLast: boolean = true) {
if (nullsLast) return sql`${column} asc nulls last`

return sql`${column} asc`
}

export function desc(
column: SQLWrapper | AnyColumn,
nullsLast: boolean = true,
) {
if (nullsLast) return sql`${column} desc nulls last`

return sql`${column} desc`
}
```

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.