agtype: return an empty list from tail() for empty and singleton lists#2399
Merged
MuhammadTahaNaveed merged 1 commit intoapache:masterfrom Apr 20, 2026
Merged
Conversation
…gleton lists
age_tail() in src/backend/utils/adt/agtype.c had an explicit early return
that mapped both the empty-list and the singleton-list cases to SQL NULL:
count = AGT_ROOT_COUNT(agt_arg);
/* if we have an empty list or only one element in the list, return null */
if (count <= 1)
{
PG_RETURN_NULL();
}
The Cypher specification (and Neo4j / Memgraph, as shown in apache#2384) both
define tail(list) as "the list without its first element". For a
zero-or-one-element input that is an empty list [], not null. Differential
tests against Neo4j surface this divergence immediately.
Remove the early return. The loop below already iterates from i=1 so it
naturally emits [] for count <= 1 and emits the correct tail for the
general case. No behaviour change for count >= 2. Tests and expected
output are updated to match the new, spec-correct result.
Fixes apache#2384
MuhammadTahaNaveed
approved these changes
Apr 20, 2026
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.
Fixes #2384.
age_tail()insrc/backend/utils/adt/agtype.chad an explicit early return that mapped both the empty-list and the singleton-list cases to SQLNULL:The Cypher specification — and Neo4j / Memgraph, as shown in the issue — both define
tail(list)as "the list without its first element". For a zero-or-one-element input that is an empty list[], notnull. Differential tests against Neo4j surface this divergence immediately.Removing the early return is enough: the loop below already iterates from
i = 1, so it naturally emits[]forcount <= 1and emits the correct tail for the general case. No behaviour change forcount >= 2.Regression tests and expected output are updated accordingly — the two "should return null" cases at the end of the
tail()section now expect[]and the comment is corrected.