# Null in greatest() function

**URL:** <https://community.questdb.com/t/null-in-greatest-function/829>\
**Category:** Community\
**Created:** [May 9, 2025, 4:12pm UTC](https://community.questdb.com/t/null-in-greatest-function/829 "2025-05-09T16:12:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BepTheWolf](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/bepthewolf/32/377_2.png) [@BepTheWolf](https://community.questdb.com/u/BepTheWolf)\
**Post date:** [May 9, 2025, 4:12pm UTC](https://community.questdb.com/t/null-in-greatest-function/829/1 "2025-05-09T16:12:23Z")

</div>

Hi, doing some testing, I noticed that if one of the arguments of greatest() function is null, this is considered the greatest value.

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [May 9, 2025, 4:54pm UTC](https://community.questdb.com/t/null-in-greatest-function/829/2 "2025-05-09T16:54:05Z")

</div>

We will look into it, it would be sensible to only provide a null if all entries are null.

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [May 12, 2025, 6:28pm UTC](https://community.questdb.com/t/null-in-greatest-function/829/3 "2025-05-12T18:28:02Z")

</div>

PR to fix it here: [fix(sql): breaking change 💥- `greatest(V)` and `least(V)` now return null only if all args are null by nwoolmer · Pull Request #5669 · questdb/questdb · GitHub](https://github.com/questdb/questdb/pull/5669)

This aligns it properly with SqlServer.

---

<div class="post-metadata">

**Author:** ![BepTheWolf](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/bepthewolf/32/377_2.png) [@BepTheWolf](https://community.questdb.com/u/BepTheWolf)\
**Post date:** [May 13, 2025, 11:04am UTC](https://community.questdb.com/t/null-in-greatest-function/829/4 "2025-05-13T11:04:21Z")

</div>

Thanks for this. I will get a lot of benefit from this

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [May 13, 2025, 11:04am UTC](https://community.questdb.com/t/null-in-greatest-function/829/5 "2025-05-13T11:04:54Z")

</div>

No problem!

Workaround for now is nesting CASE statements. It is ugly, but will work till next release.

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [May 16, 2025, 3:01pm UTC](https://community.questdb.com/t/null-in-greatest-function/829/6 "2025-05-16T15:01:04Z")

</div>

It has been merged, so should land in the next release. Let me know if you have any trouble with it!
