fix: GREATEST/LEAST should ignore null arguments - #478
Open
spokodev wants to merge 1 commit into
Open
Conversation
GREATEST and LEAST were declared without allowNullArguments, so any null argument short-circuited the whole call to null. Postgres ignores null arguments and only returns null when every argument is null. select greatest(1, null, 3); -- was null, postgres returns 3 select least(2, null, 1); -- was null, postgres returns 1
spokodev
force-pushed
the
fix/greatest-least-null-args
branch
from
August 3, 2026 20:25
2a09f88 to
692de32
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GREATESTandLEASTreturnnullas soon as any single argument is null:Postgres ignores null arguments in these functions, and returns null only when every argument is null:
Ref: Postgres conditional expressions (GREATEST/LEAST) - null values in the argument list are ignored, and the result is null only if all arguments are null.
Cause
Both functions were declared without
allowNullArguments, so a null argument short-circuited the whole call to null before the implementation ran.Fix
Set
allowNullArguments: trueand filter nulls inside the implementation, returning null only when all arguments are null. Unit tests added infunction-calls.spec.ts.