Fix subpath and subltree. Allow to return '' value.
authorTeodor Sigaev
Fri, 18 Jul 2003 13:27:43 +0000 (13:27 +0000)
committerTeodor Sigaev
Fri, 18 Jul 2003 13:27:43 +0000 (13:27 +0000)
subpath(ltree,0,0) returns ''.

contrib/ltree/expected/ltree.out
contrib/ltree/ltree_op.c

index d856f0dbabc2b06cc12da2328a0e37c050887418..a87738bf35d49ae9524097b633491f157a23ad6c 100644 (file)
@@ -74,15 +74,15 @@ SELECT subpath('Top.Child1.Child2',0,-1);
 (1 row)
 
 SELECT subpath('Top.Child1.Child2',0,0);
-      subpath      
--------------------
- Top.Child1.Child2
+ subpath 
+---------
 (1 row)
 
 SELECT subpath('Top.Child1.Child2',1,0);
-    subpath    
----------------
- Child1.Child2
+ subpath 
+---------
 (1 row)
 
 SELECT subpath('Top.Child1.Child2',0);
index 28fcfb7f7e3bfe4c053311ba54da113fd4e48924..44721bf6d0ed88a834a23dbc5bdccc02304c1e27 100644 (file)
@@ -196,12 +196,13 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos)
    ltree      *res;
    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");
 
    if (endpos > t->numlevel)
        endpos = t->numlevel;
 
+   start = end = (char *) ptr;
    for (i = 0; i < endpos; i++)
    {
        if (i == startpos)
@@ -258,7 +259,7 @@ subpath(PG_FUNCTION_ARGS)
    if (len < 0)
        end = t->numlevel + len;
    else if (len == 0)
-       end = 0xffff;
+       end = (fcinfo->nargs == 3) ? start : 0xffff;
 
    res = inner_subltree(t, start, end);