Skip to content

Commit 2c91493

Browse files
committed
Fix subpath and subltree. Allow to return '' value.
subpath(ltree,0,0) returns ''.
1 parent fd4c775 commit 2c91493

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

contrib/ltree/expected/ltree.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ SELECT subpath('Top.Child1.Child2',0,-1);
7474
(1 row)
7575

7676
SELECT subpath('Top.Child1.Child2',0,0);
77-
subpath
78-
-------------------
79-
Top.Child1.Child2
77+
subpath
78+
---------
79+
8080
(1 row)
8181

8282
SELECT subpath('Top.Child1.Child2',1,0);
83-
subpath
84-
---------------
85-
Child1.Child2
83+
subpath
84+
---------
85+
8686
(1 row)
8787

8888
SELECT subpath('Top.Child1.Child2',0);

contrib/ltree/ltree_op.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos)
196196
ltree *res;
197197
int i;
198198

199-
if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos >= endpos)
199+
if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos)
200200
elog(ERROR, "Wrong positions");
201201

202202
if (endpos > t->numlevel)
203203
endpos = t->numlevel;
204204

205+
start = end = (char *) ptr;
205206
for (i = 0; i < endpos; i++)
206207
{
207208
if (i == startpos)
@@ -258,7 +259,7 @@ subpath(PG_FUNCTION_ARGS)
258259
if (len < 0)
259260
end = t->numlevel + len;
260261
else if (len == 0)
261-
end = 0xffff;
262+
end = (fcinfo->nargs == 3) ? start : 0xffff;
262263

263264
res = inner_subltree(t, start, end);
264265

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy