Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,28 @@ $$RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1..10]$$) AS r(c agtype);
SELECT agtype_access_slice('[0]'::agtype, 'null'::agtype, '1'::agtype);
agtype_access_slice
---------------------
[0]

(1 row)

SELECT agtype_access_slice('[0]'::agtype, '0'::agtype, 'null'::agtype);
agtype_access_slice
---------------------
[0]

(1 row)

-- null bounds propagate through bracket-style slicing too
SELECT * FROM cypher('expr',
$$RETURN [1, 2, 3][1..null]$$) AS r(c agtype);
c
---

(1 row)

SELECT * FROM cypher('expr',
$$RETURN [1, 2, 3][null..2]$$) AS r(c agtype);
c
---

(1 row)

-- should error - ERROR: slice must access a list
Expand Down
5 changes: 5 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ SELECT * FROM cypher('expr',
$$RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1..10]$$) AS r(c agtype);
SELECT agtype_access_slice('[0]'::agtype, 'null'::agtype, '1'::agtype);
SELECT agtype_access_slice('[0]'::agtype, '0'::agtype, 'null'::agtype);
-- null bounds propagate through bracket-style slicing too
SELECT * FROM cypher('expr',
$$RETURN [1, 2, 3][1..null]$$) AS r(c agtype);
SELECT * FROM cypher('expr',
$$RETURN [1, 2, 3][null..2]$$) AS r(c agtype);
-- should error - ERROR: slice must access a list
SELECT * from cypher('expr',
$$RETURN 0[0..1]$$) as r(a agtype);
Expand Down
14 changes: 8 additions & 6 deletions src/backend/utils/adt/agtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -4324,11 +4324,14 @@ Datum agtype_access_slice(PG_FUNCTION_ARGS)
{
agt_lidx = AG_GET_ARG_AGTYPE_P(1);
lidx_value = get_ith_agtype_value_from_container(&agt_lidx->root, 0);
/* adjust for AGTV_NULL */
/*
* Under Cypher null-propagation semantics, list[a..b] is null when
* either bound is null. Return null directly instead of silently
* treating AGTV_NULL as an omitted bound.
*/
if (lidx_value->type == AGTV_NULL)
{
lower_index = 0;
lidx_value = NULL;
PG_RETURN_NULL();
}
}

Expand All @@ -4341,11 +4344,10 @@ Datum agtype_access_slice(PG_FUNCTION_ARGS)
{
agt_uidx = AG_GET_ARG_AGTYPE_P(2);
uidx_value = get_ith_agtype_value_from_container(&agt_uidx->root, 0);
/* adjust for AGTV_NULL */
/* Symmetric to the lower bound: null propagates to a null result. */
if (uidx_value->type == AGTV_NULL)
{
upper_index = array_size;
uidx_value = NULL;
PG_RETURN_NULL();
}
}

Expand Down
Loading