aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2003-07-18 13:27:43 +0000
committerTeodor Sigaev <teodor@sigaev.ru>2003-07-18 13:27:43 +0000
commit2c914937c144a25ae02190f8f11cd08731461d4c (patch)
tree2420646be69d1b2f7d9eb8f87f1e5c53b9e7dd44
parentfd4c775481f402dda989131edd28d365914cd528 (diff)
downloadpostgresql-2c914937c144a25ae02190f8f11cd08731461d4c.tar.gz
postgresql-2c914937c144a25ae02190f8f11cd08731461d4c.zip
Fix subpath and subltree. Allow to return '' value.
subpath(ltree,0,0) returns ''.
-rw-r--r--contrib/ltree/expected/ltree.out12
-rw-r--r--contrib/ltree/ltree_op.c5
2 files changed, 9 insertions, 8 deletions
diff --git a/contrib/ltree/expected/ltree.out b/contrib/ltree/expected/ltree.out
index d856f0dbabc..a87738bf35d 100644
--- a/contrib/ltree/expected/ltree.out
+++ b/contrib/ltree/expected/ltree.out
@@ -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);
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index 28fcfb7f7e3..44721bf6d0e 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -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);