recursive text construction in plpgsql?

From: Frank Miles <fpm(at)u(dot)washington(dot)edu>
To: <pgsql-general(at)postgresql(dot)org>
Subject: recursive text construction in plpgsql?
Date: 2001-09-07 22:38:09
Message-ID: Pine.A41.4.33.0109071534300.83830-100000@mead1.u.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The simple recursive function:

--
DROP FUNCTION testRecurse(int,int);
CREATE FUNCTION testRecurse(int,int) RETURNS text AS '
DECLARE
rslt text;
BEGIN
IF $1 = 0 THEN
rslt= CAST($2 AS TEXT);
ELSE
rslt= CAST($1 AS TEXT) || '','' || testRecurse($1 - 1, $2);
END IF;
RETURN rslt;
END;
' LANGUAGE 'plpgsql';
--

does not give the result I expect. For example, for:
SELECT testRecurse(4,3);
it seems to me that the result should be:
4,3,2,1,3
instead of what is returned:
1,1,1,1,3

Is this supposed to work in 7.1.3?

-frank

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lee Harr 2001-09-07 23:13:03 Re: Does pgsql supports full text search?
Previous Message David Ford 2001-09-07 22:29:08 Re: Problem w/ dumping huge table and no disk space