Commit 908d7b2
authored
Return an empty list from tail() for empty and singleton lists (#2399)
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) 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.1 parent 6c40838 commit 908d7b2
3 files changed
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8039 | 8039 | | |
8040 | 8040 | | |
8041 | 8041 | | |
8042 | | - | |
| 8042 | + | |
8043 | 8043 | | |
8044 | 8044 | | |
8045 | 8045 | | |
8046 | | - | |
| 8046 | + | |
8047 | 8047 | | |
8048 | 8048 | | |
8049 | 8049 | | |
8050 | 8050 | | |
8051 | 8051 | | |
8052 | | - | |
| 8052 | + | |
8053 | 8053 | | |
8054 | 8054 | | |
8055 | 8055 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3269 | 3269 | | |
3270 | 3270 | | |
3271 | 3271 | | |
3272 | | - | |
| 3272 | + | |
3273 | 3273 | | |
3274 | 3274 | | |
3275 | 3275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6056 | 6056 | | |
6057 | 6057 | | |
6058 | 6058 | | |
6059 | | - | |
6060 | | - | |
6061 | | - | |
6062 | | - | |
6063 | | - | |
| 6059 | + | |
| 6060 | + | |
| 6061 | + | |
| 6062 | + | |
| 6063 | + | |
6064 | 6064 | | |
6065 | 6065 | | |
6066 | 6066 | | |
| |||
0 commit comments