drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: GREATEST and LEAST functions

Open
#4,161 1 comment 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

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

Would be nice to be able to use the `greatest()` and `least()` functions without template literals.

For example:

```ts
const docs = await db.select({
// ...
updatedAt: greatest(document.updatedAt, documentExtra.updatedAt)
})
.from(documents)
.innerJoin(documentExtras, eq(documents.id, documentExtras.id))
```

Note that SQLite accepts additional arguments to `max` / `min` instead of using `greatest` and `least`.

Also note that PostgreSQL will return NULL only if **all** values are null, whereas MySQL returns NULL if **any** values are NULL.

Database | Functions | Docs
-- | -- | --
PostgreSQL | GREATEST/LEAST |  https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
MySQL | GREATEST/LEAST |  https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html#function_greatest / https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html#function_least
SQLite | MAX/MIN | https://sqlite.org/lang_corefunc.html#max_scalar / https://sqlite.org/lang_corefunc.html#min_scalar

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.