mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Fix subpath and subltree. Allow to return '' value.
subpath(ltree,0,0) returns ''.
This commit is contained in:
parent
fd4c775481
commit
2c914937c1
@ -74,15 +74,15 @@ SELECT subpath('Top.Child1.Child2',0,-1);
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT subpath('Top.Child1.Child2',0,0);
|
SELECT subpath('Top.Child1.Child2',0,0);
|
||||||
subpath
|
subpath
|
||||||
-------------------
|
---------
|
||||||
Top.Child1.Child2
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT subpath('Top.Child1.Child2',1,0);
|
SELECT subpath('Top.Child1.Child2',1,0);
|
||||||
subpath
|
subpath
|
||||||
---------------
|
---------
|
||||||
Child1.Child2
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT subpath('Top.Child1.Child2',0);
|
SELECT subpath('Top.Child1.Child2',0);
|
||||||
|
@ -196,12 +196,13 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos)
|
|||||||
ltree *res;
|
ltree *res;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos >= endpos)
|
if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos)
|
||||||
elog(ERROR, "Wrong positions");
|
elog(ERROR, "Wrong positions");
|
||||||
|
|
||||||
if (endpos > t->numlevel)
|
if (endpos > t->numlevel)
|
||||||
endpos = t->numlevel;
|
endpos = t->numlevel;
|
||||||
|
|
||||||
|
start = end = (char *) ptr;
|
||||||
for (i = 0; i < endpos; i++)
|
for (i = 0; i < endpos; i++)
|
||||||
{
|
{
|
||||||
if (i == startpos)
|
if (i == startpos)
|
||||||
@ -258,7 +259,7 @@ subpath(PG_FUNCTION_ARGS)
|
|||||||
if (len < 0)
|
if (len < 0)
|
||||||
end = t->numlevel + len;
|
end = t->numlevel + len;
|
||||||
else if (len == 0)
|
else if (len == 0)
|
||||||
end = 0xffff;
|
end = (fcinfo->nargs == 3) ? start : 0xffff;
|
||||||
|
|
||||||
res = inner_subltree(t, start, end);
|
res = inner_subltree(t, start, end);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user